/*
 * Class Player
 *
 * Version 1.0
 *
 * Thursday, August 14, 2008
 *
 * Created by Palidino76
 */

package palidino76.rs2.player;

import java.util.List;	
import java.util.ArrayList;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.IOException;
import java.net.Socket;
import palidino76.rs2.player.misc.*;
import palidino76.rs2.player.games.*;
import palidino76.rs2.player.skills.*;
import palidino76.rs2.player.combat.*;
import palidino76.rs2.player.quest.*;
import palidino76.rs2.player.thieving.ThievingClass;
import palidino76.rs2.player.dialogue.NPCDialogue;
import palidino76.rs2.*;
import palidino76.rs2.io.*;
import palidino76.rs2.net.PlayerSocket;
import palidino76.rs2.util.ByteVector;
import palidino76.rs2.util.Misc;
import palidino76.rs2.npcs.NPC;
import palidino76.rs2.player.items.*;
import palidino76.rs2.player.items.PlayerWeapon;
import palidino76.rs2.player.Magic;
import palidino76.rs2.player.items.PlayerItems;
import palidino76.rs2.content.skills.Mining;
import palidino76.rs2.clanchat.ClanChat;
import palidino76.rs2.content.minigames.BountyHunter;
import palidino76.rs2.content.skills.runecrafting;
import palidino76.rs2.player.ptrade.PTrade;
import palidino76.rs2.content.ge.GrandExchange;
import palidino76.rs2.content.LevelUp;

public class Player implements Entity {
	public Player target;
	public int PKPointz = 0;
	public int starter = 0;
	public int buryingBonesDelay = 0;
	public void StraightChampComplete() {
		QuestPoints++;
		frames.showInterface(this, 277);
		frames.setString(this, "You have completed Straight Champion!", 277, 4);
		frames.setString(this, ""+QuestPoints, 277, 7);
		frames.setString(this, "You can now equip the following items:", 277, 11);
		frames.setString(this, "You are rewarded 1 Quest Point.", 277, 10);
		frames.setString(this, "Fighter Torso", 277, 12);
		frames.setString(this, "", 277, 13);
		frames.setString(this, "", 277, 14);
		frames.setString(this, "", 277, 15);
		frames.setString(this, "", 277, 16);
		frames.setString(this, "", 277, 17);
		StraightChamp = 1000;
		disconnected[0] = false;
		frames.setString(this, "<col=00FF00>Straight Champion", 274, 5);
	}
	public int[] shop1 = {554,555,556,557,558,559,560,561,562,563,564,565,566,9075,1437};
	public int[] shop1n = {100,100,100,100,100,100,100,100,100,100,100,100,100,100,100};
	public int[] shop1p = {350,350,350,350,350,350,350,350,350,350,350,350,350,350,675};
	public int[] shop2 = {554,555,556,557,558,559,560,561,562,563,564,565,566,9075,1437};
	public int[] shop2n = {100,100,100,100,100,100,100,100,100,100,100,100,100,100,100};
	public int[] shop2p = {350,350,350,350,350,350,350,350,350,350,350,350,350,350,675};
	public int[] shop3 = {10828,10551,11724,11726,11728,11722,11720,11718,11732,11730,11694,11696,11698,11700,4151};
	public int[] shop3n = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
	public int[] shop3p = {55000,375000,13500000,11500000,900000,12000000,11200000,5000000,250000,8000000,22800000,18400000,50300000,28000000,1500000};
	public int[] shop4 = {301,303,305,311,590,1351,946,1265,1275};
	public int[] shop4n = {100,100,100,100,100,100,100,100,100};
	public int[] shop4p = {100,100,100,100,100,100,100,100,100};
	public int[] shop5 = {4170,4155};
	public int[] shop5n = {1,1};
	public int[] shop5p = {1,1};
	public boolean isJumping = false;
	public int shopid = 0;
	public int q1 = 0;
	public int q2 = 0;
	public int viewings = 0;
	//public int AOG = 0;
	//public int ROD = 0;
	//public int GN = 0;
	public int QuestPoints = 0;
	public String LocatedAt = "";
	public int SCSSpawn = 0;//declares if straightchamp spirit has spawned
	public int StraightChamp = 0;
	public int firstLog = 0;
	public int currentSlot = 0;
                  public int Donator = 0;
	public int poisonTicks;
	public int secHit;
	public int thirdHit;
	public int fourHit;
	public void dClaw2(Player p) {
	Player p2 = Engine.players[p.attackPlayer];
	requestAnim(2068, 0);
	requestGFX(274, 100);
	p2.appendHit((thirdHit), 0);
	p2.appendHit((fourHit), 0);
	}
	public int clawTimer;
	public boolean UseClaws; 
	public int messageTimer = 0;
	public boolean normalHomeTele = false;
	public boolean ancientsHomeTele = false;
	public int homeTele = 0;
	public int homeTeleDelay = 0;
	public GrandExchange GrandExchange =  new GrandExchange(this);  
    	public void restoreTabs(Player p) {
        		for (int b = 16; b <= 21; b++) {
            		p.frames.setInterfaceConfig(p, 548, b, false);
        		}
        		for (int a = 32; a <= 38; a++) {
            		p.frames.setInterfaceConfig(p, 548, a, false);
        		}
        		p.calculateEquipmentBonus();
        		p.frames.setInterfaceConfig(p, 548, 14, false);
        		p.frames.setInterfaceConfig(p, 548, 31, false);
        		p.frames.setInterfaceConfig(p, 548, 63, false);
       	 	p.frames.setInterfaceConfig(p, 548, 72, false);
    		}
    	public void hideTabs(Player p) {
        		for (int b = 16; b <= 21; b++) {
            		p.frames.setInterfaceConfig(p, 548, b, true);
       	 	}
        		for (int a = 32; a <= 38; a++) {
            		p.frames.setInterfaceConfig(p, 548, a, true);
        		}
        		p.calculateEquipmentBonus();
        		p.frames.setInterfaceConfig(p, 548, 14, true);
        		p.frames.setInterfaceConfig(p, 548, 31, true);
        		p.frames.setInterfaceConfig(p, 548, 63, true);
        		p.frames.setInterfaceConfig(p, 548, 72, true);
    		}
	public void homeTeleport(int telex, int teley) {
		if (homeTele == 15) {
			requestAnim(1722, 0);
		} else if (homeTele == 14) {
			requestAnim(1723, 0);
			requestGFX(800, 0);
		} else if (homeTele == 13) {
			requestAnim(1724, 0);
			requestGFX(801, 0);
		} else if (homeTele == 12) {
			requestAnim(1725, 0);
			requestGFX(802, 0);
		} else if (homeTele == 11) {
			requestAnim(2798, 0);
			requestGFX(1703, 0);
		} else if (homeTele == 10) {
			requestAnim(2799, 0);
			requestGFX(1704, 0);
		} else if (homeTele == 9) {
			requestAnim(2800, 0);
			requestGFX(1705, 0);
		} else if (homeTele == 8) {
			requestAnim(4847, 0);
			requestGFX(1706, 0);
		} else if (homeTele == 7) {
			requestAnim(4848, 0);
			requestGFX(1707, 0);
		} else if (homeTele == 6) {
			requestAnim(4849, 0);
			requestGFX(1708, 0);
		} else if (homeTele == 5) {
			requestAnim(4849, 0);
			requestGFX(1709, 0);
		} else if (homeTele == 4) {
			requestAnim(4849, 0);
			requestGFX(1710, 0);
		} else if (homeTele == 3) {
			requestAnim(4850, 0);
			requestGFX(1711, 0);
		} else if (homeTele == 2) {
			requestAnim(4851, 0);
			requestGFX(1712, 0);
		} else if (homeTele == 1) {
			requestAnim(4852, 0);
			requestGFX(1713, 0);
                        setCoords(telex, teley, 0);
                        normalHomeTele = false;
                        ancientsHomeTele = false;
	      homeTeleDelay = 3600;
                        homeTele = 15;
		}
	}
	public void finalBlow()
		{
		if (!Resizable) {
        		frames.setInterface(this, 1, 548, 5, 385);
		} else if (Resizable) {
		frames.setInterface(this, 1, 746, 5, 385);
    		}
		frames.sendMessage(this, "Your screen cracks from the mighty blow of Dharoks!");
		}
	public PTrade pTrade;
	public int Overlay = 0;
	public int OverTimer = -1;
	public int FightEnemys = 0;
	public int PitGame = -1;
	public int[] FightPeople = new int[500];
	public static int rdage[] = {10330,10332,10334,10336,10338,10340,10342,10344,10346,10348,10350,10352};
    	public static int Age() {
    		return rdage[(int)(Math.random()*rdage.length)];
    		}
	public boolean GameStarted = false;
	public boolean AtWaitRoom()
		{
		if(absX >= 2394 && absY >= 5169 && absX <= 2404 && absY <= 5175)
		{
		return true;
		}
		else
		{
		return false;
		}
	}
	public boolean VictorySkull;
	public boolean VictorySkull()
		{
		headIconSkull = 1;
		skullVanishDelay = 600;
		appearanceUpdateReq = true;
		updateReq = true;
		{
		return true;
		}
	}

	public int[] SaraPeople = new int[500];
	public int[] ZammyPeople = new int[500];
	public int CWTeam = 0;
	public int SaraFL = 0;
	public int ZamFL = 0;
	public int cwTimer;
	public int cwzamTimer;
	public boolean AtZamorakRoom(){ 
		if(absX >= 2409 && absY >= 9513 && absX <= 2432 && absY <= 9535) {
		return true;
		} else {
		return false;
		}
	}

	public boolean AtSaradominRoom() {
		if(absX >= 2367 && absY >= 9480 && absX <= 2394 && absY <= 9496) {
		return true;
		} else {
		return false;
		}
	}

	public boolean AtCastleWars() {
		if(absX >= 2363 && absY >= 3071 && absX <= 2432 && absY <= 3135) {
		return true;
		} else {
		return false;
		}
	}

	public boolean AtPits() {
		if(absX >= 2370 && absY >= 5128 && absX <= 2426 && absY <= 5167) {
		return true;
		} else {
		return false;
		}
	}
	public runecrafting runecrafting = new runecrafting();
	public int pkIcon;
	public int enemyId = 0;
	//public int pkIcon = -1;
    	public int bhTarget = 0;
    	public int penalty = 0;
    	public boolean cantLeave = false;
   	public boolean inBounty = false;
    	public int attackedBy = 0;
	public boolean magic = false;
	public boolean yew = false;
	public boolean willow = false;
	public boolean oak = false;
	public boolean reg = false;
	public int WCTimer = 0;

	public boolean isWoodcutting() {
		if (magic) {
	return true;
	}
		if (yew) {
	return true;
	}
		if (willow) {
	return true;
	}
		if (oak) {
	return true;
	}
		if (reg) {
	return true;
	}
	return false;
	}
	public int objectX = 0;
	public int objectY = 0;
	public int objectHeight = 0;
	public int firedelay = 0;
    	public void fmwalk(int x, int y) {
       		int firstX = x - (mapRegionX - 6) * 8;
        		int firstY = y - (mapRegionY - 6) * 8;
        		Engine.playerMovement.resetWalkingQueue(this);
        		Engine.playerMovement.addStepToWalkingQueue(firstX-1, firstY, this);
    		}
	public String clanRoom = "";
	public int KillJad = 0;
    	public int oreType;
    	public int oreDelay;
    	public boolean isMining;
    	public Mining mining = new Mining(this);
    	public Mining getMining() {
    		return mining;
    		}
    	public int[] miningAxes = {1265, 1267, 1269, 1271, 1273, 1275};
	public boolean Resizable = false;
	public boolean HDFS = false;
	public int abslastX = 0;
	public int abslastY = 0;
    	public int fixtimer = -1;

	public boolean splitChat = false;
    /**
     * Variable for magic defence
     */
    public boolean magicSpellHit;

    public int pID;
    public int interfaceID;

    public boolean multiZone() {
         return absX >= 3287 && absX <= 3298 && absY >= 3167 && absY <= 3178 || absX >= 3070 && absX <= 3095 && absY >= 3405 && absY <= 3448 || absX >= 2961 && absX <= 2981 && absY >= 3330 && absY <= 3354 || absX >= 2510 && absX <= 2537 && absY >= 4632 && absY <= 4660 || absX >= 3012 && absX <= 3066 && absY >= 4805 && absY <= 4858 || absX >= 2794 && absX <= 2813 && absY >= 9281 && absY <= 9305 || absX >= 3546 && absX <= 3557 && absY >= 9689 && absY <= 9700 || absX >= 2708 && absX <= 2729 && absY >= 9801 && absY <= 9829 || absX >= 3450 && absX <= 3525 && absY >= 9470 && absY <= 9535 || absX >= 3207 && absX <= 3395 && absY >= 3904 && absY <= 3903 || absX >= 3006 && absX <= 3072 && absY >= 3611 && absY <= 3712 || absX >= 3149 && absX <= 3395 && absY >= 3520 && absY <= 4000 || absX >= 2365 && absX <= 2420 && absY >= 5065 && absY <= 5120 || absX >= 2890 && absX <= 2935 && absY >= 4425 && absY <= 4470 || absX >= 2250 && absX <= 2290 && absY >= 4675 && absY <= 4715 || absX >= 2690 && absX <= 2825 && absY >= 2680 &&          absY <= 2810;
         }

    public int bestmeleeAtk() {
        if(equipmentBonus[0] > equipmentBonus[1] && equipmentBonus[0] > equipmentBonus[2]) {
            return 0;
        }
        if(equipmentBonus[1] > equipmentBonus[0] && equipmentBonus[1] > equipmentBonus[2]) {
            return 1;
        }
        return equipmentBonus[2] <= equipmentBonus[1] || equipmentBonus[2] <= equipmentBonus[0] ? 0 : 2;
        }

    public int bestmeleeDef() {
        if(equipmentBonus[5] > equipmentBonus[6] && equipmentBonus[5] > equipmentBonus[7]) {
            return 6;
        }
        if(equipmentBonus[6] > equipmentBonus[5] && equipmentBonus[6] > equipmentBonus[7]) {
            return 7;
        }
        return equipmentBonus[7] <= equipmentBonus[5] || equipmentBonus[7] <= equipmentBonus[6] ? 5 : 7;
        }

    public int meleeDef() {
        int i = equipmentBonus[bestmeleeDef()];
        int j = skillLvl[1];
        int k = getLevelForXP(1);
        int l = 0;

        if (thickSkin) {
            j = (int)((double)j + (double)k * 0.050000000000000003D);

        } else if (rockSkin) {
            j = (int)((double)j + (double)k * 0.10000000000000001D);

        } else if (steelSkin) {
            j = (int)((double)j + (double)k * 0.14999999999999999D);

        } else if (chilvaryPrayer) {
            j = (int)((double)j + (double)k * 0.20000000000000001D);

        } else if (pietyPrayer) {
            j = (int)((double)j + (double)k * 0.25D);
	}

        l += (int)((double)j + (double)j * 0.14999999999999999D + ((double)i + (double)i * 0.050000000000000003D));
        return l;
    }

    public int rangeDef() {
        int i = equipmentBonus[9];
        int j = skillLvl[1];
        int k = getLevelForXP(1);
        int l = 0;

        if (thickSkin) {
            j = (int)((double)j + (double)k * 0.050000000000000003D);

        } else if (rockSkin) {
            j = (int)((double)j + (double)k * 0.10000000000000001D);

        } else if (steelSkin) {
            j = (int)((double)j + (double)k * 0.14999999999999999D);

        } else if (chilvaryPrayer) {
            j = (int)((double)j + (double)k * 0.20000000000000001D);

        } else if (pietyPrayer) {
            j = (int)((double)j + (double)k * 0.25D);
	}

        l += (int)((double)j + (double)j * 0.14999999999999999D + ((double)i + (double)i * 0.050000000000000003D) + Misc.random(3));
        return l;
    }

    public int rangeAtk() {
        int i = equipmentBonus[4];
        int j = skillLvl[4];
        int k = getLevelForXP(4);
        int l = 0;

	if (eagleEyePrayer) {
		j = (int)((double)j + (double)k * 0.14999999999999999D);
	}

        l += (int)((double)j + (double)j * 0.14999999999999999D + ((double)i + (double)i * 0.050000000000000003D) + Misc.random(8));
        return l;
    }

    public int meleeAtk() {
        int i = equipmentBonus[bestmeleeAtk()];
        int j = skillLvl[0];
        int k = getLevelForXP(0);
        int l = 0;

        if (clarity) {
            j = (int)((double)j + (double)k * 0.050000000000000003D);

        } else if (improvedReflex) {
            j = (int)((double)j + (double)k * 0.10000000000000001D);

        } else if (incredibleReflex) {
            j = (int)((double)j + (double)k * 0.14999999999999999D);

        } else if (chilvaryPrayer) {
            j = (int)((double)j + (double)k * 0.14999999999999999D);

        } else if (pietyPrayer) {
            j = (int)((double)j + (double)k * 0.20000000000000001D);
	}

        l += (int)((double)j + (double)j * 0.14999999999999999D + ((double)i + (double)i * 0.050000000000000003D));
        return l;
    }

public void getSkillString() {
	switch (leveledUpSkill) {

		case 0:
			skillString = "Attack";
			break;
		case 1:
			skillString = "Defence";
			break;
		case 2:
			skillString = "Strength";
			break;
		case 3:
			skillString = "Hitpoints";
			break;
		case 4:
			skillString = "Ranged";
			break;
		case 5:
			skillString = "Prayer";
			break;
		case 6:
			skillString = "Magic";
			break;
		case 7:
			skillString = "Cooking";
			break;
		case 8:
			skillString = "Woodcutting";
			break;
		case 9:
			skillString = "Fletching";
			break;
		case 10:
			skillString = "Fishing";
			break;
		case 11:
			skillString = "Firemaking";
			break;
		case 12:
			skillString = "Crafting";
			break;
		case 13:
			skillString = "Smithing";
			break;
		case 14:
			skillString = "Mining";
			break;
		case 15:
			skillString = "Herblore";
			break;
		case 16:
			skillString = "Agility";
			break;
		case 17:
			skillString = "Thieving";
			break;
		case 18:
			skillString = "Slayer";
			break;
		case 19:
			skillString = "Farming";
			break;
		case 20:
			skillString = "Runecrafting";
			break;
		case 21:
			skillString = "Construction";
			break;
		case 22:
			skillString = "Hunter";
			break;
		case 23:
			skillString = "Summoning";
			break;
	}
}


    /**
     * String for leveling up
     */
    public String skillString = "";

    /**
     * Destroy item arrays
     */
    public int[] destroyItem = new int[28];
    public int[] destroyItemAmt = new int[28];

    /**
     * Destroy item variable
     */
    public int destroyItemInt;

    public boolean GoodDistance2(int objectX, int objectY, int playerX, int playerY, int distance) {
        for (int i = 0; i <= distance; i++) {
            for (int j = 0; j <= distance; j++) {
                if (objectX == playerX && ((objectY + j) == playerY || (objectY - j) == playerY || objectY == playerY)) {
                    return true;
                } else if (objectY == playerY && ((objectX + j) == playerX || (objectX - j) == playerX || objectX == playerX)) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean hasBolts() {
	switch (equipment[13]) {

	    case 9140:
	    case 9141:
	    case 9142:
	    case 9143:
	    case 9144:
	    case 9145:
	    case 9136:
	    case 9137:
	    case 9238:
	    case 9239:
	    case 9240:
	    case 9241:
	    case 9242:
	    case 9243:
	    case 9244:
	    case 9245:
		return true;
	}
	return false;
    }
    public boolean hasArrowsDB() {
	    if (equipment[13] >= 882 && equipment[13] <= 892) {
		return true;
	    }
	    if (equipment[13] == 11212) {
		return true;
	    }
		return false;
    }
    public boolean hasArrows() {
	    if (equipment[13] >= 882 && equipment[13] <= 892) {
		return true;
	    }
		return false;
    }

    public boolean wildernessArea(int absX, int absY) {
        Player p2 = Engine.players[enemyIndex];

        if (absX >= 2949 && absX <= 3400 && absY >= 3525 && absY <= 4462) {
		return true;
	}
        if (p2.duelFight()) {
            	return true;
    }
        if (duelFight()) {
            	return true;
	}
	    if (p2.AtPits()) {
            	return true;
    }
        if (AtPits()) {
            	return true;
	}
		if (p2.AtCastleWars()) {
            	return true;
    }
        if (AtCastleWars()) {
            	return true;
	}
		return false;
    }


	public void addSkillXP(double amount, int skill) {
        if(skill > skillXP.length || skill < 0) {
            return;
        }
        int oldLevel = getLevelForXP(skill);
        skillXP[skill] += amount;
        int newLevel = getLevelForXP(skill);
        if(oldLevel < newLevel) {
            if(skill == 3) {
                updateHP(newLevel - oldLevel, true);
            } else {
                skillLvl[skill] += (newLevel - oldLevel);
            }
			frames.setSkillLvl(this, skill);
			LevelUp levelup = new LevelUp(this, skill);
            appearanceUpdateReq = true;
            updateReq = true;
			levelup = null;
        }
        frames.setSkillLvl(this, skill);
    }

    public void sendCoords(Player p, int x, int y) {
        if (p == null || p.stream == null || p.disconnected[0]) {
            	return;
        }
        	stream.createFrame(177);
        	stream.writeByte(y);
        	stream.writeByteS(x);
    }

	public void createProjectile(Player p, int casterY, int casterX, int offsetY, int offsetX, int angle,
            	int speed, int gfxMoving, int startHeight, int endHeight, int lockon) {
            if (p == null || p.stream == null) {
            	return;
            }
        	sendCoords(p, (casterX - ((p.mapRegionX - 6) * 8)) - 3,
                	(casterY - ((p.mapRegionY - 6) * 8)) - 2);
        	stream.createFrame(112);
        	stream.writeByte(angle);
        	stream.writeByte(offsetX);
        	stream.writeByte(offsetY); 
        	stream.writeRShort(lockon); 
        	stream.writeWord(gfxMoving); 
        	stream.writeByte(startHeight); 
        	stream.writeByte(endHeight); 
        	stream.writeWord(51); 
        	stream.writeWord(speed); 
        	stream.writeByte(16);
        	stream.writeByte(64);							
    }

    public void createGlobalProjectile(int casterY, int casterX, int offsetY, int offsetX, int gfxMoving, int startHeight, int endHeight, int speed, int atkIndex) {
        for (Player p : Engine.players) {
            if (p == null || p.disconnected[0]) {
                continue;
            }
            createProjectile(p, casterY, casterX, offsetY, offsetX, 50,
                    speed, gfxMoving, startHeight, endHeight, atkIndex);
        }
    }

    public int attackDelay = 5;

    /**
      * Player count in clan.
      */
    public static int blackCount, whiteCount;
    /**
      * Clan wars teams
      */
    public static boolean blackTeam, whiteTeam;
    /**
      * Clan wars handler
      */
    public ClanWars clanWars = Engine.clanWars;
    /**
     * Wilderness level
     */
    public int wildLevel;
    /**
     * If player updated the Wilderness level.
     */
    public boolean updatedLevel;
    /**
     * Thieving.
     */
    public int[] thievingArray = new int[4];
    public int maxArrays = 10;
    public boolean[] optionArray = new boolean[maxArrays];
    /**
     * Quest variables
     */
    public int questId;
    public int questStage;
    public QuestDevelopment quest = new QuestDevelopment(this);
    /**
     * Has entered defence room Warrior guild.
     */
    public boolean enteredDefenceRoom;
    /**
     * Prevents XLogging.
     */
    public int combatType;
    /**
     * The delay for making a fire.
     */
    public int[] firemaking = new int[4];
    /** 
     * Next graphic creating delay for MSB Special attack
     */
    public int nextDamageDelay = -1;
    public int nextGraphicDelay = -1;
    /**
     * Item ids of which are not spawnable.
     */
    public int[] economyItems = {
	11620, 11622, 11624, 11618, 11626, 11628,11696, 11698, 11700, 11694, 11730, 3140, 11718, 11720, 11722, 11724, 11726, 11728,
	11690, 11702, 11704, 11706, 11708, 10581, 10566, 10637, 385, 391, 2440, 2434, 6685,
	11235, 4151, 12670, 12671, 4153
    };
    /**
     * Option variable
     */
    public int optionId;
    /**
     * Call Warrior guild class
     */
    public WarriorGuild warriorGuild = new WarriorGuild(this);
    /**
     * Defender dropping types variable
     */
    public int defenderId;

    /**
     * Wilderness Levels
     */
    public int wildernessLevel;

    /**
     * Summoning variables
     */
    public int summonTeleDelay = -1;
    public int summonDrainDelay = -1;
    public boolean callFamiliar;
    public boolean familiarDissMiss;
    public boolean summonedFamiliar;
	public int FamiliarID = 0;

    /**
     * Warrior Guild variables
     */
    public int[] randomItemIds = {
	8843, 8844, 8845, 8846, 8847, 8848, 8849, 8850
    };
    public String warriorArmour;

    /**
     * autoCast Variables
     */
    public int[] regularStaffs = {
	1381, 1387
    };
    public int[] otherStaffs = {
	4675, 1383
    };
    public int autoCastDmgDelay = -1;
    public int autoCastDelay;
    public int[] autoCast = new int[3];
    public boolean castAuto;
    public boolean usingAutoCast;
    /**
     * If player is disturbing commander zilyana.
     */
    public boolean disturbSara;
    /**
     * Death Delays
     */
    public int randomDelay = -1;
    /**
     * Yell delay
     */
    public int massYellDelay = 0;

    /**
     * Crystal bow shots.
     */
    public int crystalShots;

    /**
     * Fight Cave variables
     */
    public int neededKills;
    public int[] waveType = new int[5];
    public int waveCount;
    public int waveDelay = -1;
    public FightCave fCave = new FightCave(this);

    /**
     * Fletching variables
     */
    public int deletedItem, addedItem;
    public int fletchAmt;
    public boolean isFletching;
    public int[] fletching;
    public int fletchDelay;
    public int fletchType, fletchExp;
    PlayerFletching fletchingClass = new PlayerFletching(this);

    public int equipSpecDelay;

    public int jumpDelay = 0;
    public boolean jumpUpdateReq = false;
    public boolean isBanking;

    /**
     * Dueling variables
     */
    public int countDelay = -1;
    public int countType = -1;
    public boolean duelDeath;
    public boolean acceptDuel;
    public boolean acceptScreen1, acceptScreen2;
    public DuelArena duelArena = new DuelArena(this);
    public int duelFriend;
    public boolean duelScreen1, duelScreen2;

    public int explodeType;
    public int explodeDelay = -1;

    public int[] godWarsKills = new int[5];

    public int watchId = -1;

    public int spellType;

    public int playerStart;

    public boolean muteExpect, muteExpect2;
    public int muteType;
    public int[] hugeNpcs = {
	50, 1155, 1157, 1158, 1160, 2745, 6222, 6203
    };

    /**
     * Woodcutting variables
     */
    public int cutDelay;
    public boolean isWoodcutting;

    /**
     * Dueling variables
     */
    public boolean isBusy;
    public int duelEnemy;
    public boolean inDuelFight;

    /**
     * Pet variables
     */
    public int petKeeper;
    public boolean summonedPet;

    /**
     * Mage Arena variables
     */
    public int kolodionDelay;
    public boolean arenaActive;

    /**
     * Slayer variables
     */
    public int slayerAmount1;
    public int slayerType1;
    public int[] slayerType = {
	1615, 5363, 55, 54
    };
    public boolean slayerTask;
    public int[] slayerArray = {
	1, 2, 3, 4
    };
    public int slayerAmount;

    /**
     * Pvn variables
     */
    public int damageSpecDelay = -1;
    public boolean enableSpecDamage;
    public int damageDelay1 = -1;
    public boolean enableDamage;
    public int atkDelay;
    public boolean attackingNpc;
    public int attackNpc;

    /**
     * Clan wars variables.
     */
    public boolean blackClan;
    public boolean whiteClan;

    /**
     * Thieving variables.
     */
    public int pickPocketDelay;

    /**
     * This variable is added to add facing if player is gonna pickpocket.
     */
    public int npcClick2;

    /**
     * Wilderness variables.
     */
    public int wildyLevel;

    /**
     * Potions
     */
    public boolean atkPot;
    public boolean strPot;
    public boolean defPot;
    public boolean rangePot;
    public int potionType;
    public boolean usingPotion;
    public int statDelay;

    /**
     * Emote clicking delay.
     */ 
    public int animClickDelay;

    /**
     * Prayer variables
     */
    public int buryDelay;
    public int drainDelay;
    public boolean usingPrayer;
    public int headIconPrayer = -1;
	public boolean usingBH;
	public int headIconBH = -1;
    public boolean magicPrayer;
    public boolean rangedPrayer;
    public boolean meleePrayer;
    public boolean retriPrayer;
    public boolean redempPrayer;
    public boolean smitePrayer;

    public boolean thickSkin;
    public boolean rockSkin;
    public boolean steelSkin;

    public boolean burstOfStr;
    public boolean superHumanStr;
    public boolean ultimateStr;

    public boolean protItem;

    public boolean clarity;
    public boolean improvedReflex;
    public boolean incredibleReflex;

    public boolean eagleEyePrayer;
    public boolean mysticMightPrayer;
    public boolean chilvaryPrayer;
    public boolean pietyPrayer;

    /**
     * Magic combat variables
     */
    public int magicDelay = 0;
    public int freezeDelay;
    public int stunDelay;
    public int vengDelay;
    public boolean usingVeng;
    public int vengUseDelay;
    public int mageDelay;
    public int magicDamageDelay = -1;

    /**
     * Agility Variables
     */
    public int[] agilityX = {
	2476, 2475, 2474, 2473, 2472, 2471
    };
    public int[] agilityY = {
	3426
    };
    public boolean agilityPerforming;
    public int agilityDelay;
    public int agilityType;

    /**
     * Combat variables
     */
    public boolean fadeAway;
    public int enemyFadeAwayDelay = -1;
    public int fightStyle = 1;
    public int[] strangeItems = {
	6570
    };
    public int battleCDelay;
    public int battleCount;
    public int poisonDelay;
    public int poisonHitCount;
    public boolean isPoisoned;
    public int headIconSkull = -1;
	public int headIconBounty = -1;
    public boolean isSkulled;
	public boolean isSBounty;
    public int skullVanishDelay;
    public int rangeDmgDelay;
    public boolean rangeDamage;
    public int[] rangeBows = {
	841, 843, 845, 847, 849, 851, 853,
	855, 857, 859, 861, 9174, 9176, 9177,
	9179, 9181, 9183, 9185
    };
    public int[] rangeArrows = {
	882, 884, 886, 888, 890, 892
    };
    public int[] godSwords = {
	11620, 11622, 11618, 11624, 11626, 11628, 11694, 11696, 11698, 11700
    };
    public int myBonus;
    public int meleeDef;
    public int waitDeathDelay = -1;
    public boolean randomVariable;
    public int deathDelay = -1;
    public boolean isDead;
    public int specDelay = -1;
    public int specDelay2 = -1;
    public int specDelay3 = -1;
    public boolean expectSpec;
    public boolean autoAttack;
    public int specFillDelay = 90;
    public boolean usingSpecial;
    public int specAmount;
    public int damageDelay;
    public boolean gonnaDamage;
    public int combatDelay;
    public int resetEnemy;
    public int enemyIndex;
    public boolean attackingPlayer;
    public boolean magicOnPlayer;

    /**
     * Eat delay
     */
    public int eatDelay;
    /**
     * Player's index.
     */
    public int playerId = 0;
    /**
     * Class for storing and converting bytes.
     */
    public ByteVector stream = new ByteVector(500, 5000);
    /**
     * Player's socket for handling most io operations.
     */
    public PlayerSocket socket;
    /**
     * Set to true if the player has finished the login stage.
     */
    public boolean online = false;
    /**
     * Player's username.
     */
    public String username = "null";
    /**
     * Player's password.
     */
    public String password = "";
    /**
     * Player's rights.
     */
    public int rights = 0;
    /**
     * 1 set to true means socket disconnected but logged in, both for removing the player.
     */
    public boolean[] disconnected = new boolean[2];

    /**
     * Gives quick access to the frame class.
     */
    public Frames frames = Engine.frames;

    /**
     * The region this player is in.
     */
    public int mapRegionX = 0;
    public int mapRegionY = 0;
    /**
     * The position this player is at in the map region.
     */
    public int currentX = 0;
    public int currentY = 0;
    /**
     * Absolute coordinates this player is at.
     */
    public int absX = 0;
    public int absY = 0;
	    /**
     * KilledBy.
     */
    public int[] killedBy = new int[Engine.players.length];
    /**
     * The height level this player is at.
     */
    public int heightLevel = 0;
    /**
     * If either are above -1 then the player is in motion.
     */
    public int walkDir = -1;
    public int runDir = -1;
    /**
     * True if the player is running, false if it isn't.
     */
    public boolean isRunning = false;

    public boolean Mouse = false;
    public boolean Chat = false;
    public boolean Split = false;
    public boolean Aid = false;
    /**
     * Set to true if the player has entered a new map region.
     */
    public boolean mapRegionDidChange = false;
    /**
     * Set to true if teleported.
     */
    public boolean didTeleport = false;
    /**
     * Set Absolute coordinates to these.
     */
    public int teleportToX = -1;
    public int teleportToY = -1;
    /**
     * True if the player is Reqing an update.
     */
    public boolean updateReq = false;
    /**
     * Max number of steps this player can have pending.
     */
    public int walkingQueueSize = 50;
    public int wQueueReadPtr = 0;
    public int wQueueWritePtr = 0;
    /**
     * Positions the player is Reqing to walk to.
     */
    public int[] walkingQueueX = new int[walkingQueueSize];
    public int[] walkingQueueY = new int[walkingQueueSize];
    public int[] walkingQueue = new int[walkingQueueSize];
    /**
     * All the players within distance.
     */
    public Player[] playerList = new Player[Engine.players.length];
    /**
     * All the players stored in distance.
     */
    public byte[] playersInList = new byte[Engine.players.length];
    public int playerListSize = 0;
    /**
     * True if chatting is Reqing to be sent.
     */
    public boolean chatTextUpdateReq = false;
    public String chatText = "";
    public int chatTextEffects = 0;
    /**
     * True if an appearance update is needed.
     */
    public boolean appearanceUpdateReq = false;
    /**
     * Animation data.
     */
    public boolean animUpdateReq = false;
    public int animReq = -1;
    public int animDelay = 0;
    /**
     * GFX data.
     */
    public boolean gfxUpdateReq = false;
    public int gfxReq = -1;
    public int gfxDelay = 0;
    /**
     * Player and NPC facing data.
     */
    public boolean faceToUpdateReq = false;
    public int faceToReq = -1;
    /**
     * Damage data.
     */
    public boolean hit1UpdateReq = false;
    public boolean hit2UpdateReq = false;
    public int hitDiff1 = 0;
    public int hitDiff2 = 0;
    public int posionHit1 = 0;
    public int posionHit2 = 0;
    /**
     * Skill level data.
     */
    public int[] skillLvl = new int[25];
    public int[] skillXP = new int[25];
    public int combatLevel = 0;
    /**
     * Equipment data.
     */
    public int[] equipment = new int[14];
    public int[] equipmentN = new int[14];
    public int[] equipmentBonus = new int[12];
    /**
     * Player appearance.
     */
    public int[] color = new int[5];
    public int[] look = new int[7];
    public int npcType = -1;
    public int gender = 0;
    /**
     * Player emotes.
     */
    public int runEmote = 0x338;
    public int walkEmote = 0x333;
    public int standEmote = 0x328;
    /**
     * All the NPCs within distance.
     */
    public NPC[] npcList = new NPC[Engine.npcs.length];
    /**
     * All the npcs stored in distance.
     */
    public byte[] npcsInList = new byte[Engine.npcs.length];
    public int npcListSize = 0;
    /**
     * Rebuild the entire NPC list.
     */
    public boolean rebuildNPCList = false;
    /**
     * An array storing all the players items.
     */
    public int[] items = new int[28];
    public int[] itemsN = new int[28];
    /**
     * Open interfaces, use these to confirm an interface is open when trying to use one.
     */
    public int interfaceId = -1;
    public int chatboxInterfaceId = -1;
    /**
     * The current position in the login stage.
     */
    public int loginStage = 0;
    /**
     * Click x position.
     */
    public int clickX = 0;
    /**
     * Click y position.
     */
    public int clickY = 0;
    /**
     * Click id.
     */
    public int clickId = 0;
    /**
     * True if the player is trying to pickup an item.
     */
    public boolean itemPickup = false;
    /**
     * Set run energy.
     */
    public boolean runEnergyUpdateReq = false;
    /**
     * Amount of current run energy.
     */
    public int runEnergy = 100;
    /**
     * Delay before run energy can increase.
     */
    public int runEnergyDelay = 0;
    /**
     * Clicked the first option on a player.
     */
    public boolean playerOption1 = false;
    /**
     * Clicked the second option on a player.
     */
    public boolean playerOption2 = false;
    /**
     * Clicked the third option on a player.
     */
    public boolean playerOption3 = false;
    /**
     * Clicked the first option on a NPC.
     */
    public boolean npcOption1 = false;
    /**
     * Clicked the first option on an object.
     */
    public boolean objectOption1 = false;
    /**
     * Setting the prayer system effects.
     */
    public PrayerSystem prayerSystem = new PrayerSystem(this);
    /**
     * Setting the players weapon.
     */
    public PlayerWeapon playerWeapon = new PlayerWeapon(this);
    /**
     * Clicked the second option on an object.
     */
    public boolean objectOption2 = false;
    /**
     * Clicked the second option on a NPC.
     */
    public boolean npcOption2 = false;
    /**
     * Forced chat.
     */
    public String forceChat = "";
    public boolean forceChatUpdateReq = false;
    /**
     * Stat restore delay.
     */
    public int statRestoreDelay = 150;
    /**
     * Teleporting variables.
     */
    public int teleX = -1;
    public int teleY = -1;
    public int teleDelay = -1;
    public int teleFinishGFX = 0;
    public int teleFinishGFXHeight = 0;
    public int teleFinishAnim = 0;
    /**
     * Delay before recieving packets.
     */
    public int clickDelay = -1;
    public long loginTimeout = System.currentTimeMillis();
    public int[] bankItems = new int[Engine.playerBank.SIZE];
    public int[] bankItemsN = new int[Engine.playerBank.SIZE];
	public int[] tabStartSlot = new int[11];
	public int viewingBankTab = 10;
	public boolean withdrawNote;
	public boolean insertMode;

    /**
     * Constructs a new Player.
     * @param socket The socket this Player belongs to.
     * @param id The index this player is at.
     */
    public Player(Socket socket, int id) {
		GrandExchange = new GrandExchange(this);
        this.socket = new PlayerSocket(this, socket);
        playerId = id;
	look[0] = 0;
	look[1] = 10;
        look[2] = 18;
        look[3] = 26;
        look[4] = 33;
        look[5] = 36;
        look[6] = 42;
        for (int i = 0; i < skillLvl.length; i++) {
	    skillLvl[i] = 1;
	    skillXP[i] = 0;
	    skillLvl[3] = 10;
	    skillXP[3] = 1155;
        }
        for (int i = 0; i < items.length; i++) {
            items[i] = -1;
	    itemsN[i] = 0;
        }
        for (int i = 0; i < equipment.length; i++) {
            equipment[i] = -1;
        }
        for (int i = 0; i < bankItems.length; i++) {
            bankItems[i] = -1;
        }
		pTrade = new PTrade(this);
    }

    public boolean skillCapeEquiped() {
	for (int i = 10639; i < 10663; i++) {
		for (int j = 9747; j < 9812; j++) {
			if (equipment[1] == i || equipment[1] == j || equipment[1] == 12169 || equipment[1] == 12170) { 
				return true;
			}
		}
	}
    return false;
    }

    /**
     * This method is called every 600 milliseconds.
     * <p>While this is good for for changing integers, this
     * should not be abused. Things that can be handled else where should
     * be done in that way, such as clicking the accept button in trade
     * should update in the ActionsButton class rather than Reqing
     * an update for the process to handle.
     */
    public void process() {
	if(clawTimer > 0) clawTimer--;
	if(clawTimer == 0 && UseClaws)
	{
	dClaw2(this);
	UseClaws = false;
	} 
        if (homeTeleDelay > 0){
            homeTeleDelay--;
        }
        if (homeTele > 0 && homeTeleDelay <= 0 && normalHomeTele){
            homeTeleport(3221,3221);
            homeTele--;
        }
        if (homeTele > 0 && homeTeleDelay <= 0 && ancientsHomeTele){
            homeTeleport(3087,3496);
            homeTele--;
        }

	if (buryingBonesDelay > 0) {
        buryingBonesDelay--;
		return;
    }
//DUEL ARENA//
//if (Server.engine.players[duelFriend] != null) {
//Server.engine.players[duelFriend].frames.setHintIcon(this, 10, 1, 1, -1);
//}
//START OF CASTLEWARS PROCESS//
if(AtCastleWars() && Engine.CWGameTime < 1)
{
if(CWTeam == 0 && Engine.SaradominScore > Engine.ZamorakScore)
{
Engine.playerItems.addItem(this, 4067, 3);
frames.sendMessage(this, "Your team won!");
}
if(CWTeam == 0 && Engine.SaradominScore < Engine.ZamorakScore)
{
frames.sendMessage(this, "Your team lost!");
}
if(CWTeam == 1 && Engine.SaradominScore < Engine.ZamorakScore)
{
Engine.playerItems.addItem(this, 4067, 3);
frames.sendMessage(this, "Your team won!");
}
if(CWTeam == 1 && Engine.SaradominScore > Engine.ZamorakScore)
{
frames.sendMessage(this, "Your team lost!");
}
setCoords(2440+Misc.random(4), 3085+Misc.random(10), 0);
OverTimer = 2;
equipment[1] = -1; 
equipmentN[1] = 0; 
appearanceUpdateReq = true; 
updateReq = true; 
frames.setItems(this, 387, 28, 94, equipment, equipmentN);

if(equipment[3] == 4037 && CWTeam == 1)
{
Engine.SaradominFlag = false;
equipment[3] = -1; 
equipmentN[3] = 0; 
appearanceUpdateReq = true; 
updateReq = true; 
frames.setItems(this, 387, 28, 94, equipment, equipmentN);
}
if(equipment[3] == 4039 && CWTeam == 0)
{
Engine.ZamorakFlag = false;
equipment[3] = -1; 
equipmentN[3] = 0; 
appearanceUpdateReq = true; 
updateReq = true; 
frames.setItems(this, 387, 28, 94, equipment, equipmentN);
}
}


for(Player pg : Engine.players) {
if(pg != null)
{
Player ph = Engine.players[pg.playerId];


Engine.SaradominTeam = SaraPeople[1]+
SaraPeople[2]+SaraPeople[3]+SaraPeople[4]+SaraPeople[5]+
SaraPeople[6]+SaraPeople[7]+SaraPeople[8]+SaraPeople[9]+
SaraPeople[10]+SaraPeople[11]+SaraPeople[12]+SaraPeople[13]+
SaraPeople[14]+SaraPeople[15]+SaraPeople[16]+SaraPeople[17]+
SaraPeople[18]+SaraPeople[19]+SaraPeople[20]+SaraPeople[21]+
SaraPeople[22]+SaraPeople[23]+SaraPeople[24]+SaraPeople[25]+
SaraPeople[26]+SaraPeople[27]+SaraPeople[28]+SaraPeople[29]+
SaraPeople[30]+SaraPeople[31]+SaraPeople[32]+SaraPeople[33];
if(AtSaradominRoom()){
pg.SaraPeople[playerId] = 1;
}
else
{
pg.SaraPeople[playerId] = 0;
}


Engine.ZamorakTeam = ZammyPeople[1]+
ZammyPeople[2]+ZammyPeople[3]+ZammyPeople[4]+ZammyPeople[5]+
ZammyPeople[6]+ZammyPeople[7]+ZammyPeople[8]+ZammyPeople[9]+
ZammyPeople[10]+ZammyPeople[11]+ZammyPeople[12]+ZammyPeople[13]+
ZammyPeople[14]+ZammyPeople[15]+ZammyPeople[16]+ZammyPeople[17]+
ZammyPeople[18]+ZammyPeople[19]+ZammyPeople[20]+ZammyPeople[21]+
ZammyPeople[22]+ZammyPeople[23]+ZammyPeople[24]+ZammyPeople[25]+
ZammyPeople[26]+ZammyPeople[27]+ZammyPeople[28]+ZammyPeople[29]+
ZammyPeople[30]+ZammyPeople[31]+ZammyPeople[32]+ZammyPeople[33];
if(AtZamorakRoom()){
pg.ZammyPeople[playerId] = 1;
}
else
{
pg.ZammyPeople[playerId] = 0;
}
}
}




if(AtSaradominRoom() && Engine.CWarsTimer < 1)
{
OverTimer = 5;
setCoords(2425+Misc.random(4), 3075+Misc.random(4), 1);
CWTeam = 0;
}
if(AtZamorakRoom() && Engine.CWarsTimer < 1)
{
OverTimer = 5;
setCoords(2370+Misc.random(4), 3128+Misc.random(4), 1);
CWTeam = 1;
}

if(AtZamorakRoom() || AtSaradominRoom())
{
frames.setString(this, "Time till game starts:", 653, 7);
frames.setString(this, (Engine.CWarsTimer/2)+"", 653, 8);
Overlay = 1;
frames.setOverlay(this, 653);
}

if(AtCastleWars())
{
if(Engine.SaradominFlag == false)
{
frames.setString(this, "Safe", 58, 4);
}
else
{
frames.setString(this, "<col=ff0000>Taken", 58, 4);
}
if(Engine.ZamorakFlag == false)
{
frames.setString(this, "Safe", 58, 5);
}
else
{
frames.setString(this, "<col=ff0000>Taken", 58, 5);
}
frames.setString(this, "Zamorak: "+Engine.ZamorakScore, 58, 0);
frames.setString(this, "Saradomin: "+Engine.SaradominScore, 58, 1);
frames.setString(this, ""+Engine.CWGameTime, 58, 8);
if(Overlay == 0)
{
frames.setOverlay(this, 58);
Overlay = 1;
}
}
//END OF CASTLEWARS PROCESS//
//START OF FIGHT PITS//
	if(PitGame > 0) PitGame -= 1;
if(OverTimer > 0) OverTimer -= 1;
if(OverTimer == 0)
{
OverTimer -= 1;
Overlay = 0;
}

if(!AtPits() && !AtWaitRoom() && !AtZamorakRoom() && !AtSaradominRoom() && !AtCastleWars() && Overlay == 0)
{
Overlay = 1;
frames.removeOverlay(this);
}
if(PitGame == 0 && AtPits() && GameStarted == false)
{
if(FightEnemys > 1)
{
GameStarted = true;
frames.showChatboxInterface(this, 241);
frames.animateInterfaceId(this, 9847, 241, 2);
frames.setNPCId(this, 2617, 241, 2);
frames.setString(this, "TzHaar-Mej-Jal", 241, 3);
frames.setString(this, "Fight!", 241, 4);
NpcDialogue = 0;
NpcDialogueSend = true;
Overlay = 0;
}
else
{
GameStarted = false;
frames.sendMessage(this, "No Enemy's to fight.");
Engine.FightPitTimer = 120;
setCoords(2395+Misc.random(8), 5170+Misc.random(4), 0);
Overlay = 0;
}
}

if(AtPits() && FightEnemys < 2 && GameStarted == true)
{
GameStarted = false;
setCoords(2395+Misc.random(8), 5170+Misc.random(4), 0);
frames.sendMessage(this, "You are victorious!");
headIconSkull = 1;
appearanceUpdateReq = true;
updateReq = true;
Engine.playerItems.addItem(this, 995, 1000000);
skillLvl[3] = getLevelForXP(3);
frames.setSkillLvl(this, 3);        
Engine.FightPitTimer = 120;
Overlay = 0;
for(Player pe : Engine.players) {
if(pe != null)
{
frames.sendMessage(pe, "<col=FF00FF>"+Misc.optimizeText(username)+ " Level: " +combatLevel+" won the battle of the fight pits." );
}
}
}
if(AtPits())
{
frames.setString(this, "Players:", 653, 7);
frames.setString(this, FightEnemys+"", 653, 8);
if(Overlay == 0)
{
frames.setOverlay(this, 653);
Overlay = 1;
}
}
else
if(AtWaitRoom())
{
if(Engine.FightPitTimer > 0)
{
frames.setString(this, "Time till game starts:", 653, 7);
frames.setString(this, (Engine.FightPitTimer/2)+"", 653, 8);
if(Overlay == 0)
{
frames.setOverlay(this, 653);
Overlay = 1;
}
}
else
{
frames.setString(this, "Game has begun", 653, 7);
frames.setString(this, "", 653, 8);
if(Overlay == 0)
{
Overlay = 1;
frames.setOverlay(this, 653);
}
}
}

if(Engine.FightPitTimer >= 0 && Engine.FightPitTimer <= 2 && AtWaitRoom())
{
setCoords(2392+Misc.random(13), 5152+Misc.random(10), 0);
frames.showChatboxInterface(this, 241);
frames.animateInterfaceId(this, 9847, 241, 2);
frames.setNPCId(this, 2617, 241, 2);
frames.setString(this, "TzHaar-Mej-Jal", 241, 3);
frames.setString(this, "Please Wait until I call the fight to start.", 241, 4);
NpcDialogue = 0;
NpcDialogueSend = true;
PitGame = 20;
Overlay = 0;
}

for(Player pe : Engine.players) {
if(pe != null)
{
Player pt = Engine.players[pe.playerId];
if(AtPits())
{
pe.FightPeople[playerId] = 1;
}
else
{
pe.FightPeople[playerId] = 0;
}

FightEnemys = FightPeople[1]+
FightPeople[2]+FightPeople[3]+FightPeople[4]+FightPeople[5]+
FightPeople[6]+FightPeople[7]+FightPeople[8]+FightPeople[9]+
FightPeople[10]+FightPeople[11]+FightPeople[12]+FightPeople[13]+
FightPeople[14]+FightPeople[15]+FightPeople[16]+FightPeople[17]+
FightPeople[18]+FightPeople[19]+FightPeople[20]+FightPeople[21]+
FightPeople[22]+FightPeople[23]+FightPeople[24]+FightPeople[25]+
FightPeople[26]+FightPeople[27]+FightPeople[28]+FightPeople[29]+
FightPeople[30]+FightPeople[31]+FightPeople[32]+FightPeople[33];

Engine.playersingame = FightEnemys;
}
}
//END OF FIGHT PITS//
		if(penalty > 0) {
	    penalty--;
	    if(!cantLeave) {
	        frames.setString(this, "Pickup Penalty:", 653, 10);
	    } else {
		frames.setString(this, "Can't leave for:", 653, 10);
	    }
	    frames.setString(this, "" + penalty/2, 653, 11);
	    if(penalty == 0) {
		frames.setInterfaceConfig(this, 653, 9, true);
	    }
	}
	if (isWoodcutting()) {
requestAnim(Engine.woodpatch.getAnim(this), 0);
}
if (WCTimer > 0) {
WCTimer--;
}
if (WCTimer == 0) {
Engine.woodpatch.checkWC(this);
}
		if (firedelay > 0) {
	    firedelay--;
	}
	if (firedelay == 0) {
	    frames.createGlobalObject(-1, objectHeight, objectX, objectY, 0, 10);
            Engine.items.createGroundItem(592, 1, objectX, objectY, heightLevel, username);
	    firedelay = -1;
	}
	     if (oreDelay > 0) {
    oreDelay--;
        }
        if (oreDelay == 0 && isMining) {
    getMining().receiveOre();
        }
		    if (fixtimer > 0) {
            fixtimer--;
		}
	
		if (fixtimer == 0) {
	    if (Resizable = false) {
	frames.setWindowPane(this,548);
	setCoords(abslastX, abslastY, 0);
	fixtimer = -1;
	    } else {
	frames.setWindowPane(this,549);
	setCoords(abslastX, abslastY, 0);
	fixtimer = -1;
	    }
	}
	getDuelClass().process();
	getSkillString();
	System.gc();


	if (cookTimer > 0) {
		cookTimer--;
	}
	if (cookTimer == 0) {
	    if (cookAmount == 0) {
		cookTimer = -1;
	    } else {
		Cook(this, cookXP, cookID, cookGet, cookName);
	    }
	}
	if (fishTimer > 0) {
		fishTimer--;
	}
	if (fishTimer == 0) {
		Fish(this, fishXP, fishGet, fishEmote, fishName);
	}
	if (thiefDelay > 0) {
	    thiefDelay--;
	}
	if (thiefTimer > 0) {
	    thiefTimer--;
	}
	if (hitTimer > 0) {
	    hitTimer--;
	}
	if (hitTimer == 1) {
	    requestAnim(getBlockAnim1(), 0);
	    requestGFX(245, 100);
	    appendHit(Misc.random(getThiefHit()), 0);
	}
	if (thiefDelay == 1) {
	    ThievingClass thief = new ThievingClass(this);
	    thief.ThiefFinish(this);
	}

	if (surgeonTimer > 0) {
	    surgeonTimer--;
	}
	if (surgeonTimer == 3) {
	    skillLvl[3] = getLevelForXP(3);
	    frames.setSkillLvl(this, 3);
	    frames.playSound(this, 2892, 1, 0);
	}
	if (surgeonTimer == 1) {
	    NpcWanneTalk = 964;
	    NpcDialogueSend = false;
	}

if(absX >= 3150 && absY >= 3476 && absX <= 3181 && absY <= 3505)//Grand Exchange
{
LocatedAt = "Grand Exchange.";
}
else if(absX >= 2652 && absY >= 3294 && absX <= 2670 && absY <= 3314)//Thieve
{
LocatedAt = "Thieving Market.";
}
else if(absX >= 2835 && absY >= 3533 && absX <= 2878 && absY <= 3556)//Combat Training
{
LocatedAt = "Combat Guild.";
}
else if(absX >= 2530 && absY >= 3543 && absX <= 2553 && absY <= 3558)//Agility
{
LocatedAt = "Barbarian Agility Course.";
}
else if(absX >= 3041 && absY >= 3477 && absX <= 3062 && absY <= 3505)//Monastary
{
LocatedAt = "Monastary.";
}
else if(absX >= 2652 && absY >= 3409 && absX <= 2685 && absY <= 3449)//Range Guild
{
LocatedAt = "Archery Guild.";
}
else if(absX >= 2692 && absY >= 3417 && absX <= 2711 && absY <= 3433)//Wc and fm
{
LocatedAt = "Woodcutting and Firemaking masters.";
}
else if(absX >= 2538 && absY >= 3077 && absX <= 2619 && absY <= 3108)//Yanille
{
LocatedAt = "Yanille";
}
else if(absX >= 2100 && absY >= 4800 && absX <= 2200 && absY <= 4900)//Runecrafting
{
LocatedAt = "Chaos rune altar.";
}
else if(absX >= 2918 && absY >= 3477 && absX <= 2933 && absY <= 3491)//Herblore
{
LocatedAt = "Herblore area.";
}
else if(absX >= 2915 && absY >= 3430 && absX <= 2937 && absY <= 3456)//Summoning
{
LocatedAt = "Summoning area.";
}
else if(absX >= 2804 && absY >= 3457 && absX <= 2816 && absY <= 3470)//Farming
{
LocatedAt = "Farming area.";
}
else if(absX >= 2798 && absY >= 3431 && absX <= 2841 && absY <= 3445)//Catherby
{
LocatedAt = "Catherby.";
}
else if(absX >= 2928 && absY >= 3275 && absX <= 2950 && absY <= 3290)//Crafting Guild
{
LocatedAt = "Crafting Guild.";
}
else if(absX >= 3156 && absY >= 3367 && absX <= 3272 && absY <= 3511)//Varrock
{
LocatedAt = "Varrock.";
}
else if(absX >= 3362 && absY >= 3228 && absX <= 3391 && absY <= 3241)//Duel
{
LocatedAt = "Duel Arena.";
}
else if(AtCastleWars())
{
LocatedAt = "Castle Wars";
}
else if(AtSaradominRoom())
{
LocatedAt = "Saradomin Waiting room.";
}
else if(AtZamorakRoom())
{
LocatedAt = "Zamorak Waiting room.";
}
else if(absX >= 2256 && absY >= 4680 && absX <= 2287 && absY <= 4711)//Slayer Cave
{
LocatedAt = "Slayer Cave.";
}
else if(absX >= 2370 && absY >= 5128 && absX <= 2426 && absY <= 5165)//Fight Pits
{
LocatedAt = "Fight Pits.";
}
else if(absX >= 2394 && absY >= 5169 && absX <= 2404 && absY <= 5175)//Fight Pits Waitin Room
{
LocatedAt = "Fight Pit waiting room.";
}
else if(absY >= 3522)//Wilderness
{
LocatedAt = "Wilderness.";
}
else
{
LocatedAt = "Not in any of the main areas, must be wandering around.";
}

	if (isInDuelArena()) {
		frames.playMusic(this, 122);
	/*} else {
		frames.playMusic(this, 1);*/
	}

	if (NpcWanneTalk > 0) {
		if (Misc.getDistance(absX, absY, clickX, clickY) <= 2) {
			NpcDialogue = NpcWanneTalk;
			NpcWanneTalk = NpcDialogue;
		}
	}

	if (thievingType > 0 && thiefNPC) {
		if (Misc.getDistance(absX, absY, clickX, clickY) <= 1) {
			ThievingClass thief = new ThievingClass(this);
			thief.ThiefStart(this);
		}
	}

	if (NpcDialogue > 0 && NpcDialogueSend == false) {
		NPCDialogue nD = new NPCDialogue(this);
		nD.NPCDialogue(this);
	}

	if (!magicPrayer && !rangedPrayer && !meleePrayer && !retriPrayer && !redempPrayer && !smitePrayer && !thickSkin 
		&& !rockSkin && !steelSkin && !burstOfStr && !superHumanStr && !ultimateStr && !clarity && !improvedReflex 
		&& !incredibleReflex && !eagleEyePrayer && !mysticMightPrayer && !chilvaryPrayer && !pietyPrayer && !protItem) {
	    usingPrayer = false;
	}

	if (resetAnimTimer > 0) {
	    resetAnimTimer--;
	}
	if (resetAnimTimer == 1) {
	    	animUpdateReq = true;
            	animUpdateReq = true;
            	updateReq = true;
	}
	if (npcContactTimer > 0) {
	    npcContactTimer--;
	}
	if (npcContactTimer == 1) {
	    frames.setOverlay(this, 429);
	}
	if (switchBackTimer > 0) {
	    switchBackTimer--;
	}
	if (switchBackTimer == 1) {
	    frames.setTab(this, 79, 430);
	    frames.sendMessage(this, "Your magics switch back to Lunar.");
	}
	if (dreamTimer > 0) {
	    dreamTimer--;
	}
	if (dreamTimer == 9) {
	    requestAnim(6296, 0);
	    requestGFX(1056, 0);
	}
	if (dreamTimer == 2) {
	    requestAnim(6297, 0);
	}
	if (cmbResetTimer > 0) {
	    cmbResetTimer--;
	}
	if (cmbResetTimer == 1) {
	    combatWith = 0;
	}
	if (msbDelay > 0){
            msbDelay--;
        }
	if (msbDelay == 0){
	    requestGFX(256, 100);
            msbDelay = -1;
        }
        if (disconnected[0]) {
			if (pTrade.getPartner() != null) {
                pTrade.declineTrade();
            }
            disconnected[1] = true;
		if (clanRoom.length() > 0) {
            Engine.clanChat.leave(this);
            }
        }

	    if (jumpDelay > 0) {
            jumpDelay--;
            jumpUpdateReq = true;
        }
		
        if (jumpUpdateReq) {
            if (jumpDelay >= 1) {
                runEmote = walkEmote = 2750;
                updateReq = appearanceUpdateReq = true;
            }		
            if (jumpDelay <= 0) {
                playerWeapon.setWeapon();
                jumpDelay = 0;
                updateReq = appearanceUpdateReq = true;
            }
            jumpUpdateReq = false;
        }

	/**
	 * Warrior Guild
	 */
	if (!enteredDefenceRoom) {
		if (absX == 2842 && absY == 3545 && heightLevel == 1)
			getWarriorClass().addWarriorDefenceEvent();
		enteredDefenceRoom = false;
	}
	if (thievingArray[0] > 0)
	    thievingArray[0]--;
	if (thievingArray[0] == 0) {
	    PlayerThieving thievClass = new PlayerThieving(this);
	    thievClass.addStallThievingEvent();
	}
	if (thievingArray[3] > 0)
	    thievingArray[3]--;
	if (nextGraphicDelay > 0)
	    nextGraphicDelay--;
	if (nextGraphicDelay == 0) {
	    PlayerCombat playerAttacking = new PlayerCombat(this);
	    playerAttacking.addNextAttack();
	}
	if (nextDamageDelay > 0)
	    nextDamageDelay--;
	if (nextDamageDelay == 0) {
	    PlayerCombat playerAttacking = new PlayerCombat(this);
	    playerAttacking.addNextDamage();
	}
	if (fletchDelay > 0)
	    fletchDelay--;

	if (fletchDelay == 0 && isFletching)
	    getFletchingClass().appendFletchingEngine();

	if (summonTeleDelay > 0) {
	    summonTeleDelay--;
	}
	if (summonTeleDelay == 0) {
	    setCoords(3069, 10257, 0);
	    summonTeleDelay = -1;
	    requestAnim(715, 0);
	}
	if (autoCastDmgDelay > 0) {
	    autoCastDmgDelay--;
	}
	if (autoCastDmgDelay == 0) {
	    PlayerMagic magicSystem = new PlayerMagic(this);
	    magicSystem.createAutoCastDamageEvent();
	}
	if (randomDelay > 0) {
	    randomDelay--;
	}
	if (randomDelay == 0) {
		Server.engine.newNPC(2862, this.absX-1, this.absY, this.heightLevel, 0, 0, 0, 0, false, 0);
	    requestAnim(7197, 0);
	    isDead = true;
		frames.showInterface(this, 122);
	    deathDelay = 6;
	    randomDelay = -1;
	}
	if (autoCastDelay > 0)
	    autoCastDelay--;
	if (autoCastDelay == 0 && usingAutoCast) {
	    PlayerMagic magic = new PlayerMagic(this);
	    magic.createAutoCastEvent();
	}

	if (massYellDelay > 0) {
	    massYellDelay--;
	}
        if (statRestoreDelay > 0) {
            statRestoreDelay--;
        }
        if (clickDelay > 0) {
            clickDelay--;
        }
        if (teleDelay > 0) {
            teleDelay--;
        }
	if (equipSpecDelay > 0) {
	    equipSpecDelay--;
	}
	if (waveDelay > 0) {
	    waveDelay--;
	}
	if (waveDelay == 0) {
	    fCave.fightSystem();
	}
	if (countDelay > 0) {
	    countDelay--;
	}
	if (countDelay == 0) {
	    if (countType >= 0) {
	    	if (countType == 3) {
			requestForceChat("3");
	    	} else if (countType == 2) {
			requestForceChat("2");
	    	} else if (countType == 1) {
			requestForceChat("1");
	   	} else if (countType == 0) {
			requestForceChat("BITCH LETS FIGHT!");
	    	}
	    	countType--;
	    	countDelay = 3;
	    } else {
		countType = -1;
		countDelay = -1;
	    }
	}
	if (explodeDelay > 0) {
	    explodeDelay--;
	}
	if (explodeDelay == 0) {
	    appendPotion();
	}
	if (eatDelay > 0) {
	    eatDelay--;
	}
        if (magicDelay > 0) {
            magicDelay--;
        }
	if (rangeDmgDelay > 0) {
	    rangeDmgDelay--;
	}
	if (rangeDmgDelay == 0 && rangeDamage) {
	    PlayerCombat PC2 = new PlayerCombat(this);
	    PC2.appendRangeDamage();
	}
	if (damageSpecDelay > 0) {
	    damageSpecDelay--;
	}
	if (damageSpecDelay == 0 && enableSpecDamage) {
	    PlayerCombat playCb2 = new PlayerCombat(this);
	    playCb2.appendNpcDamageMeleeSpec();
	}
	if (damageDelay1 > 0) {
	    damageDelay1--;
	}
	if (damageDelay1 == 0 && enableDamage) {
	    PlayerCombat playerCb = new PlayerCombat(this);
	    playerCb.appendNpcDamageMelee();
	}
	if (atkDelay > 0) {
	    atkDelay--;
	}
	if (atkDelay == 0 && attackingNpc) {
	    PlayerCombat playCb = new PlayerCombat(this);
	    playCb.attackNpc();
	}
	if (buryDelay > 0) {
	    buryDelay--;
	}
	if (battleCDelay > 0) {
	    battleCDelay--;
	}
	if (battleCDelay == 0) {
	    battleCount = 0;
	    battleCDelay = -1;
	}
	if (pickPocketDelay > 0) {
	    pickPocketDelay--;
	}
	if (magicDamageDelay > 0) {
	    magicDamageDelay--;
	}
	if (!AtPits() && !AtWaitRoom() && headIconSkull == 1)
	{
	headIconSkull = -1;
	appearanceUpdateReq = true;
	updateReq = true;
	frames.sendMessage(this, "You have lost your Victory skull because you have left the Fight Pits area.");
	}
	if (skullVanishDelay > 0) {
	    skullVanishDelay--;
	}
	if (skullVanishDelay == 0 && isSkulled) {
		headIconSkull = -1;
		isSkulled = false;
		frames.sendMessage(this, "The skull has randomly dissappeared.");
		skullVanishDelay = 0;
		appearanceUpdateReq = true;
		updateReq = true;
	}
	if (drainDelay > 0) {
	    drainDelay--;
	}
	if (drainDelay == 0 && usingPrayer) {
	    drainPrayer();
	}
	if (statDelay > 0) {
	    statDelay--;
	}
	if (statDelay == 0 && usingPotion) {
	    updateStats();
	}
	if (poisonDelay > 0) {
	    poisonDelay--;
	}
	if (isPoisoned && poisonDelay == 0) {
	    appendHit(Misc.random(6), 1);
	    if (posionHit1 == 0) {
		posionHit1 = 4;
	    }
	    poisonHitCount++;
	    poisonDelay = 45;
	}
	if (isPoisoned && poisonHitCount >= 7) {
	    isPoisoned = false;
	    poisonHitCount = 0;
	    frames.sendMessage(this, "Poison has faded away..");
	}
	if (specAmount >= 0 && specAmount <= 249) {
		frames.setConfig2(this, 300, 0);
	}
	if (specAmount >= 250 && specAmount <= 499) {
		frames.setConfig2(this, 300, 250);
	}
	if (specAmount >= 500 && specAmount <= 749) {
		frames.setConfig2(this, 300, 500);
	}
	if (specAmount >= 750 && specAmount <= 999) {
		frames.setConfig2(this, 300, 750);
	}
	if (specAmount >= 1000) {
		frames.setConfig2(this, 300, 1000);
	}
	if (specFillDelay > 0) {
	    specFillDelay--;
	}
	if (specFillDelay == 0) {
	  if (specAmount <= 999) {
	    if (specAmount <= 1000) {
			specAmount += 100;
			specFillDelay = 25;
	    }
	  }
	}
	if (freezeDelay > 0) {
	    freezeDelay--;
	}
	if (stunDelay > 0) {
	    stunDelay--;
	}
	if (vengDelay > 0) {
	    vengDelay--;
	}
	if (vengUseDelay > 0) {
	    vengUseDelay--;
	}
	if (vengUseDelay <= 0 && usingVeng) {
	    vengUseDelay = 0;
	    usingVeng = false;
	    frames.sendMessage(this, "Vengeance has faded away.");
	}
	if (animClickDelay > 0) {
	    animClickDelay--;
	}
	if (agilityDelay > 0) {
	    agilityDelay--;
	}
	if (agilityDelay == 0 && agilityPerforming) {
	    PlayerAgility pa = new PlayerAgility(this);
	    pa.resetPerforming();
	}
	if (deathDelay > 0) {
	    deathDelay--;
	}
	if (waitDeathDelay > 0) {
	    waitDeathDelay--;
	}
	if (skillLvl[3] <= 0 && waitDeathDelay == -1 && !randomVariable && !duelFight() && !AtPits() && !AtCastleWars()) {
		//dropAllStuff();
		//dropAllItems(getPlayerKiller());
		dropStuff(enemyIndex);
	    waitDeathDelay = 3;
	    resetAttack();
	    randomDelay = 3;
	}
	if (skillLvl[3] <= 0 && waitDeathDelay == -1 && !randomVariable && AtCastleWars()) {
	    waitDeathDelay = 3;
	    resetAttack();
	    randomDelay = 3;
	}
	if (skillLvl[3] <= 0 && waitDeathDelay == -1 && !randomVariable && duelFight()) {
	    waitDeathDelay = 3;
	    resetAttack();
	    randomDelay = 3;
		duelDeath = true;
	    randomVariable = true;
	    isDead = true;
	}
	if (deathDelay == 0 && isDead) {
	    reLocatePlayer();
	}
	if (combatDelay > 0) {
	    combatDelay--;
	}
	if (attackingPlayer) {
	    PlayerCombat pc = new PlayerCombat(this);
	    pc.attackPlayer();
	}
	if (damageDelay > 0) {
	    damageDelay--;
	}
	if (damageDelay == 0 && gonnaDamage) {
	    PlayerCombat PC = new PlayerCombat(this);
	    PC.appendDamages();
	}
	if (mageDelay > 0) {
	    mageDelay--;
	}
	if (specDelay > 0) {
	    specDelay--;
	}
	if (specDelay == 0) {
	    PlayerCombat PC1 = new PlayerCombat(this);
	    PC1.appendSpecDamage();
	}
	if (specDelay2 > 0) {
	    specDelay2--;
	}
	if (specDelay2 == 0) {
	    PlayerCombat PC1 = new PlayerCombat(this);
	    PC1.appendSpecDamage2();
	}
	if (specDelay3 > 0) {
	    specDelay3--;
	}
	if (specDelay3 == 0) {
	    PlayerCombat PC1 = new PlayerCombat(this);
	    PC1.appendSpecDamage3();
	}
        if (runEnergyDelay > 0) {
            runEnergyDelay--;
        } else {
            if (runEnergy < 100) {
                runEnergy++;
                runEnergyUpdateReq = true;
            }
            runEnergyDelay = 4;
        }
        if (itemPickup) {
            Engine.packets.pickupItem.handlePacket(this, 0, 0);
        }
        if (playerOption1) {
            Engine.packets.playerOption1.handlePacket(this, 0, 0);
        }
        if (playerOption2) {
            Engine.packets.playerOption2.handlePacket(this, 0, 0);
        }
        if (playerOption3) {
            Engine.packets.playerOption3.handlePacket(this, 0, 0);
        }
        if (npcOption1) {
            Engine.packets.npcOption1.handlePacket(this, 0, 0);
        }
        if (npcOption2) {
            Engine.packets.npcOption2.handlePacket(this, 0, 0);
        }
        if (objectOption1) {
            Engine.packets.objectOption1.handlePacket(this, 0, 0);
        }
        if (objectOption2) {
            Engine.packets.objectOption2.handlePacket(this, 0, 0);
        }
        if (runEnergyUpdateReq) {
            frames.setEnergy(this);
            runEnergyUpdateReq = false;
        }
        if (statRestoreDelay <= 0) {
        	int xpLvl = getLevelForXP(3);
                if (skillLvl[3] < xpLvl) {
                    skillLvl[3]++;
                    frames.setSkillLvl(this, 3);
                } else if (skillLvl[3] > xpLvl) {
                    skillLvl[3]--;
                    frames.setSkillLvl(this, 3);
                }
            	statRestoreDelay = 150;
        }
	addWildernessUpdating();
        if (teleDelay == 0) {
            teleDelay = -1;
            setCoords(teleX, teleY, heightLevel);
            requestAnim(teleFinishAnim, 0);
            requestGFX(teleFinishGFX, teleFinishGFXHeight);
            teleX = teleY = -1;
        }
        if (clickDelay == 0) {
            clickDelay = -1;
        }
    }

    public void reLocatePlayer() {
	if (deathDelay == 0 && isDead) {
		if (inJadCave()) {
			getFightClass().deleteFightNPCs();
		}
		waveCount = 0;
		waveDelay = -1;

		if (retriPrayer) {
			requestGFX(437, 0);
			prayerSystem.appendRetributionEffect(14);
			retriPrayer = false;
		}

		deathDelay = -1;
		isDead = false;

		/*if (Server.engine.wildernessArea(absX, absY) && !clanWarsFightArea() && !blackTeam && !whiteTeam) {
			dropStuff(enemyIndex);
		}*/

		for (int i = 0; i < skillLvl.length; i++) {
			skillLvl[i] = getLevelForXP(i);
		}

		arenaActive = false;
		requestFaceTo(65535);
		vengUseDelay = 0;
		vengDelay = 0;
		usingVeng = false;

		for (int i = 0; i < 1000; i++) {
			requestAnim(playerWeapon.getStandEmote(equipment[3]), 0);
		}

		waitDeathDelay = -1;
		randomVariable = false;
		poisonHitCount = 0;
		isPoisoned = false;
		poisonDelay = 0;
		resetPrayer();
		freezeDelay = 0;
		frames.showInterface(this, 177);
		frames.sendMessage(this,"Oh dear! You have died.");
		frames.sendMessage(this,"If you cannot move then click somewhere on the minimap.");
		specAmount = 1000;
		combatWith = 0;

		if (this != null && Server.engine.players[enemyIndex] != null && enemyIndex > 0) {
			Server.engine.players[enemyIndex].enemyIndex = 0;
		}
		//START OF DEATH FOR CASTLEWARS//
if(AtCastleWars())
{
if(CWTeam == 0)
{
setCoords(2425+Misc.random(4), 3075+Misc.random(4), 1);
}
else
{
setCoords(2370+Misc.random(4), 3128+Misc.random(4), 1);
}
if(equipment[3] == 4037 && CWTeam == 1)
{
Engine.SaradominFlag = false;
equipment[3] = -1; 
equipmentN[3] = 0; 
appearanceUpdateReq = true; 
updateReq = true; 
frames.setItems(this, 387, 28, 94, equipment, equipmentN);
}
if(equipment[3] == 4039 && CWTeam == 0)
{
Engine.ZamorakFlag = false;
equipment[3] = -1; 
equipmentN[3] = 0; 
appearanceUpdateReq = true; 
updateReq = true; 
frames.setItems(this, 387, 28, 94, equipment, equipmentN);
}
}
//END OF DEATH FOR CASTLEWARS//
		if(inBounty) {
		Player p2 = Engine.players[enemyIndex];
		    int i = heightLevel;
		    if(p2 != null) {
			if(p2.bhTarget != playerId) {
		    	p2.penalty = 360;
			    p2.frames.setInterfaceConfig(p2, 653, 9, false);
			} else {
		    	    if(i == 0) {
				p2.bhTarget = Engine.BountyHunter.getTargetLow(this);
		            } else if(i == 4) {
				p2.bhTarget = Engine.BountyHunter.getTargetMid(this);
	  	    	    } else {
				p2.bhTarget = Engine.BountyHunter.getTargetHigh(this);
		      	    }
		    	    Player p3 = Engine.players[p2.bhTarget];
		    	    if(p3 != null) {
					p2.frames.setString(p2, "Target:" , 653, 7);
	    	   		p2.frames.setString(p2, "" + p3.username , 653, 8);
		    	    } else {
					p2.frames.setString(p2, "Target:" , 653, 7);
	    			p2.frames.setString(p2, "None" , 653, 8);
		    	    }
			}
		    }
		    frames.removeOverlay(this);
		    pkIcon = -1;
		    appearanceUpdateReq = updateReq = true;
		    if(i == 0) {
		        Engine.BountyHunter.removeLow(this);
		    } else if(i == 4) {
			Engine.BountyHunter.removeMid(this);
	  	    } else {
			Engine.BountyHunter.removeHigh(this);
		    }
		    setCoords(3172, 3675, 0);
		} else {
                    setCoords(3661, 3497, 0);
		}
		if (AtPits()) {
			GameStarted = false;
			setCoords(2395, 5170, 0);
			frames.sendMessage(this, "You lost. Please wait until the other players are done fighting for the next game.");
			headIconSkull = -1;
			appearanceUpdateReq = true;
			updateReq = true;
		}
		if (duelFight()) {
			if (Server.engine.players[duelFriend] != null) {
				Server.engine.players[duelFriend].setCoords(3376 + Misc.random(2), 3275 + Misc.random(2), 0);
				Server.engine.players[duelFriend].specAmount = 1000;
				Server.engine.players[duelFriend].frames.setConfig2(Server.engine.players[duelFriend], 300, 1000);
				Server.engine.players[duelFriend].frames.showInterface(Server.engine.players[duelFriend], 633);
				Server.engine.players[duelFriend].frames.setString(Server.engine.players[duelFriend], Misc.optimizeText(username), 633, 22);
				Server.engine.players[duelFriend].frames.setString(Server.engine.players[duelFriend], ""+combatLevel+"", 633, 21);
				Server.engine.players[duelFriend].frames.sendMessage(Server.engine.players[duelFriend], "Congratulations, You've won the challenge.");
				for (int i = 0; i < Server.engine.players[duelFriend].skillLvl.length; i++)
					Server.engine.players[duelFriend].skillLvl[i] = Server.engine.players[duelFriend].getLevelForXP(i);
				Server.engine.players[duelFriend].frames.setSkillLvl(Server.engine.players[duelFriend], 3);
				Server.engine.players[duelFriend].frames.setSkillLvl(Server.engine.players[duelFriend], 5);
				getDuelClass().resetDuelSettings1();
			}
			duelDeath = false;
		}

		if (duelFight()) {
			setCoords(3358 + Misc.random(1), 3269 + Misc.random(1), 0);
		} else if (clanWarsFightArea()) {
			if (whiteTeam) {
				setCoords(3320, 3771, 0);
			} else {
				setCoords(3320, 3780, 0);
				}
		} else if (!duelFight() && !clanWarsFightArea() && !AtPits()) {
		        setCoords(3087, 3489, 0);
		}

		frames.removeOverlay(this);
		headIconBounty = -1;
		skullVanishDelay = 0;
		isSkulled = false;
		frames.setConfig2(this, 300, 1000);
		frames.setSkillLvl(this, 3);
		frames.setSkillLvl(this, 5);
		enemyIndex = 0;
		appearanceUpdateReq = true;
		updateReq = true;
	}
    }

    /**
     * Resets attack.
     */
    public void resetAttack() {
	PlayerMethods pm = new PlayerMethods(this);
	PlayerCombat playCb = new PlayerCombat(this);
	playCb.setNpcAttack(false);
	playCb.setAtkDelay(0);
	pm.setAttackPlayer(false);
	pm.setMagicPlayer(false);
	pm.specialAttack(false);
	pm.setCombatDelay(0);
	disturbSara = false;
	magicOnPlayer = false;
    }

    /**
     * Get xp based on your level.
     * @param skillId The skill level to get the level based off XP for.
     * @return Returns the level based on the amount of XP the specified skill has.
     */
    public int getLevelForXP(int skillId) {
        int exp = skillXP[skillId];
        int points = 0;
        int output = 0;
        for (int lvl = 1; lvl < 100; lvl++) {
            points += Math.floor((double)lvl + 300.0 * Math.pow(2.0, (double)lvl / 7.0));
            output = (int)Math.floor(points / 4);
            if ((output - 1) >= exp) {
                return lvl;
            }
        }
        return 99;
    }

    /**
     * Calculates equipment bonus.
     */
    public void calculateEquipmentBonus() {
        for (int i = 0; i < equipmentBonus.length; i++) {
            equipmentBonus[i] = 0;
        }
        for (int i = 0; i < equipment.length; i++) {
            if (equipment[i] > -1) {
                for (int j = 0; j < Engine.items.maxListedItems; j++) {
                    if (Engine.items.itemLists[j] != null) {
                        if (Engine.items.itemLists[j].itemId == equipment[i]) {
                            for (int k = 0; k < equipmentBonus.length; k++) {
                                equipmentBonus[k] += Engine.items.itemLists[j].bonuses[k];
                            }
                            break;
                        }
                    }
                }
            }
        }
    }

    /**
     * Writes the equipment bonus.
     */
    public void setEquipmentBonus() {
        String[] bonusNames = Misc.bonusNames;
        int id = 35;
        for (int i = 0; i < equipmentBonus.length; i++) {
            frames.setString(this, bonusNames[i] + ": " + (equipmentBonus[i] >= 0 ? "+" : "") + equipmentBonus[i], 667, id++);
            if (id == 45) {
                id = 47;
            }
        }
        frames.setString(this, "Summoning: +0", 667, 45);
    }

	public void openBank() {
		frames.setConfig2(this, 563, 4194304); //???
		//frames.setConfig2(this, 1248, -2013265920);
		frames.setConfig(this, 115, withdrawNote ? 1 : 0);
		frames.setConfig(this, 305, insertMode ? 1 : 0);
		Engine.playerBank.sendTabConfig(this);
		frames.showInterface(this, 762);
		frames.setInventory(this, 763);
		frames.setString(this, "The Bank of Drowning508" , 762, 24);
		frames.setBankOptions(this);
		frames.setItems(this, -1, 64207, 95, bankItems, bankItemsN);
		frames.setItems(this, -1, 64209, 93, items, itemsN);
		//frames.hideTabs(this); code to hide inventory & tabs
		viewingBankTab = 10;
		frames.setString(this, ""+Engine.playerBank.getFreeBankSlot(this), 762, 97);
		frames.setString(this, ""+Engine.playerBank.SIZE, 762, 98);
		isBanking = true;
	}

    public void updateHP(int chHp, boolean heal) {
        if (heal) {
            skillLvl[3] += chHp;
            if (skillLvl[3] > getLevelForXP(3)) {
                skillLvl[3] = getLevelForXP(3);
            }
        } else if (!heal) {
            skillLvl[3] -= chHp;
            if (skillLvl[3] <= 0) {
                skillLvl[3] = 0;
		randomDelay = 4;
                isDead = true;
                Engine.playerMovement.resetWalkingQueue(this);
            }
        }
        frames.setSkillLvl(this, 3);
    }

    /**
     * Teleports a player.
     * @param x The x coordinate to teleport to.
     * @param y The y coordinate to teleport to.
     * @param height The height level to teleport to.
     * @param delay The delay before the teleport is done.
     * @param distance The offset you can teleport to, such as 1 for a max offset of x +/- 1 and y +/- 1.
     * @param emoteStart The emote to do right away.
     * @param emoteEnd The emote to do after teleporting.
     * @param gfxStart The graphic to do right away.
     * @param gfxStartH The height level to create the start graphic at.
     * @param gfxEnd The graphic to do after the teleport is done.
     * @param gfxEndH The finish graphic height.
     */
    public void teleportTo(int x, int y, int height, int delay, int distance, int emoteStart, int emoteEnd, int gfxStart, int gfxStartH, int gfxEnd, int gfxEndH) {
        itemPickup = false;
        playerOption1 = false;
        playerOption2 = false;
        playerOption3 = false;
        npcOption1 = false;
        npcOption2 = false;
        objectOption1 = false;
        objectOption2 = false;
        attackingPlayer = false;
        clickDelay = delay + 2;
        teleDelay = delay;
        if (distance > 0) {
            int xType = Misc.random(1);
            int yType = Misc.random(1);
            int xOffset = Misc.random(distance);
            int yOffset = Misc.random(distance);
            if (xType == 1)
                x += -xOffset;
            else
                x += xOffset;
            if(yType == 1)
                y += -yOffset;
            else
                y += yOffset;
        }
        teleX = x;
        teleY = y;
        heightLevel = height;
        Engine.playerMovement.resetWalkingQueue(this);
        requestAnim(emoteStart, 0);
        requestGFX(gfxStart, gfxStartH);
        teleFinishGFX = gfxEnd;
        teleFinishGFXHeight = gfxEndH;
        teleFinishAnim = emoteEnd;
    }

    /**
     * Set the player's coordinates.
     * @param x The x coordinate to teleport to.
     * @param y The y coordinate to teleport to.
     */
    public void setCoords(int x, int y, int height) {
        teleportToX = x;
        teleportToY = y;
        heightLevel = height;
        didTeleport = true;
    }

    /**
     * Req an animation for this player.
     * @param animId The amination to perform.
     * @param animD The delay before doing the animation.
     */
    public void requestAnim(int animId, int animD) {
        animReq = animId;
        animDelay = animD;
        animUpdateReq = true;
        updateReq = true;
    }

    /**
     * Req an graphic for this player.
     * @param gfxId The graphic to perform.
     * @param gfxD The delay or height or the gfx depending on the value.
     */
    public void requestGFX(int gfxId, int gfxD) {
        if (gfxD >= 100) {
            gfxD += 6553500;
        }
        gfxReq = gfxId;
        gfxDelay = gfxD;
        gfxUpdateReq = true;
        updateReq = true;
    }

    /**
     * Req this player faces NPC or player.
     * @param faceId The target to face.
     */
    public void requestFaceTo(int faceId) {
        faceToReq = faceId;
        faceToUpdateReq = true;
        updateReq = true;
    }

    /**
     * Append damage.
     */
    public void appendHit(int damage, int posion) {
        if (damage > skillLvl[3]) {
            damage = skillLvl[3];
        }
        updateHP(damage, false);
        if (!hit1UpdateReq) {
            hitDiff1 = damage;
            posionHit1 = posion;
            hit1UpdateReq = true;
        } else {
            hitDiff2 = damage;
            posionHit2 = posion;
            hit2UpdateReq = true;
        }
        updateReq = true;
    }

    /**
     * Append damage.
     */
    public void append1Hit(int damage, int posion) {
        if (damage > skillLvl[3]) {
            damage = skillLvl[3];
        }
        updateHP(damage, false);
        if (!hit2UpdateReq) {
            hitDiff2 = damage;
            posionHit2 = posion;
            hit2UpdateReq = true;
        } else {
            hitDiff1 = damage;
            posionHit1 = posion;
            hit1UpdateReq = true;
        }
        updateReq = true;
    }

    /**
     * Block anims.
     */
    public int getBlockAnim() {
	if (equipment[3] == 4031) {
		return 221;
	}
	if (equipment[3] == 11235 || equipment[3] == 851 || equipment[3] == 853 || equipment[3] == 855 || equipment[3] == 857 || equipment[3] == 859 || equipment[3] == 861) {
		return 424;
	}
	if (equipment[5] == 8850 || equipment[5] == 8849
				 || equipment[5] == 8848
				 || equipment[5] == 8847
				 || equipment[5] == 8846
				 || equipment[5] == 8845
				 || equipment[5] == 8844) {
		return 4177;
	}
	if (equipment[3] == 4587 && equipment[5] != 8850 && equipment[5] != 8849 && equipment[5] != 8848 && equipment[5] != 8847 && equipment[5] != 8846 && equipment[5] != 8845 && equipment[5] != 8844) {
		return 404;
	}
    return 1156;
    }

    /**
     * Block anims.
     */
    public int getBlockAnim1() {
	if (equipment[3] == 4031) {
		return 221;
	}
	if (equipment[3] == 4151 && equipment[5] != 8850) {
		return 1659;
	}
	if (equipment[3] == 4718 ||
	    equipment[3] == -1) {
		return 424;
	}
	if (equipment[5] == 8850 || equipment[5] == 8849
				 || equipment[5] == 8848
				 || equipment[5] == 8847
				 || equipment[5] == 8846
				 || equipment[5] == 8845
				 || equipment[5] == 8844) {
		return 4177;
	}
	if (equipment[3] == 4755) {
		return 2063;
	}
	if (equipment[3] == 4587 && equipment[5] != 8850 && equipment[5] != 8849 && equipment[5] != 8848 && equipment[5] != 8847 && equipment[5] != 8846 && equipment[5] != 8845 && equipment[5] != 8844) {
		return 404;
	}
	if (equipment[3] == 6528) {
		return 424;
	}
	if (equipment[3] == 10887) {
		return 5866;
	}
	if (equipment[3] == 4153) {
		return 1666;
	}
	if (equipment[3] == 11694 ||
	    equipment[3] == 11696 ||
	    equipment[3] == 11698 ||
	    equipment[3] == 11700 ||
	    equipment[3] == 1307 ||
	    equipment[3] == 1309 || 
            equipment[3] == 1311 || 
	    equipment[3] == 1313 || 
	    equipment[3] == 1315 ||
	    equipment[3] == 1317 ||
	    equipment[3] == 1319 ||
	    equipment[3] == 7158 ||
	    equipment[3] == 11730) {
		return 7050;
	}
	if (equipment[3] == 3204) {
		return 424;
	}
    return 424;
    }

    /**
     * Force chat text.
     */
    public void requestForceChat(String s) {
        forceChat = s;
        forceChatUpdateReq = true;
        updateReq = true;
    }

    public int getArmourDef() {
	switch (equipment[4]) {

		case 1127: return 80;
		case 4712: return 120;
		case 4757: return 140;
		case 4720: return 140;
		case 3140: return 100;
		case 10551: return 70;
		case 11720: return 215;
		case 11724: return 220;
	}
    return 10;
    }

    public int getRangeArmourDef() {
	switch (equipment[4]) {

		case 1135: return 115;
		case 2499: return 140;
		case 2501: return 165;
		case 2503: return 190;
		case 11720: return 200;
	}
    return 40;
    }

    public int getRangeBonus() {
	switch (equipment[3]) {

		case 841: return 65;
		case 843: return 80;
		case 845: return 85;
		case 847: return 90;
		case 849: return 95;
		case 851: return 100;
		case 853: return 120;
		case 855: return 130;
		case 857: return 150;
		case 859: return 165;
		case 861: return 180;
		case 9185: return 280;
		case 11235: return 160;
	}
    return 60;
    }

    public boolean hitPlayer(int enemyIndex) {
	if (getRandom(equipmentBonus[10]) > getRandom(Engine.players[enemyIndex].equipmentBonus[4] + Engine.players[enemyIndex].getArmourDef())) {
		return true;
	}
    return false;
    }

    public boolean hitPlayerRange() {
	if (getRandom(equipmentBonus[8] + getRangeBonus()) > getRandom(Engine.players[enemyIndex].equipmentBonus[9] + Engine.players[enemyIndex].getRangeArmourDef())) {
		return true;
	}
    return false;
    }

    public boolean hitNpcRange() {
	PlayerCombat playCb = new PlayerCombat(this);
	if (getRandom(equipmentBonus[8] + getRangeBonus()) > getRandom(playCb.getNpcDefenceRange())) {
		return true;
	}
    return false;
    }

    private int getRandom(int range) {
        return (int)(Math.random() * (range + 1));
    }

    /**
     * Gives experience to a player.
     * @param amount The amount which will gives to the player
     * @param skillId the skill Id of the player which the exp will go to.
     */
    public void appendExperience(int amount, int skillId) {
	int oldLvl = getLevelForXP(skillId);
	if (skillXP[skillId] > 200000000 || amount >= 2147000000) {
		skillXP[skillId] = 13100000;
		return;
	}
	skillXP[skillId] += amount;
	int newLvl = getLevelForXP(skillId);
	resetSkills();
	if (oldLvl < newLvl) {
		skillLvl[skillId] += (newLvl - oldLvl);
		switch (skillId) {

			case 0:
				leveledUpSkill = 0;
				leveledUp[0] = true;
				frames.sendMessage(this, "You've just advanced an Attack level! You have reached level " + skillLvl[0] + ".");
				frames.setString(this, "Congratulations, you have just advanced an Attack level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[0] + "!", 740, 1);
				frames.setConfig(this, 1179, 0);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Attack level!");
				//player.frames.sendMessage(player, "<col=FF0000>Congratulations "+Misc.optimizeText(username)+" has just reached level 99 Attack!");
			break;

			case 1:
				leveledUpSkill = 1;
				leveledUp[1] = true;
				frames.sendMessage(this, "You've just advanced a Defence level! You have reached level " + skillLvl[1] + ".");
				frames.setString(this, "Congratulations, you have just advanced an Defence level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[1] + "!", 740, 1);
				frames.setConfig(this, 1179, 1);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Defence level!");
			break;

			case 2:
				leveledUpSkill = 2;
				leveledUp[2] = true;
				frames.sendMessage(this, "You've just advanced a Strength level! You have reached level " + skillLvl[2] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Strength level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[2] + "!", 740, 1);
				frames.setConfig(this, 1179, 2);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Strength level!");
			break;

			case 3:
				leveledUpSkill = 3;
				leveledUp[3] = true;
				frames.sendMessage(this, "You've just advanced a HitPoints level! You have reached level " + skillLvl[3] + ".");
				frames.setString(this, "Congratulations, you have just advanced a HitPoints level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[3] + "!", 740, 1);
				frames.setConfig(this, 1179, 3);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new hitpoints level!");
			break;

			case 4:
				leveledUpSkill = 4;
				leveledUp[4] = true;
				frames.sendMessage(this, "You've just advanced an Ranged level! You have reached level " + skillLvl[4] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Ranged level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[4] + "!", 740, 1);
				frames.setConfig(this, 1179, 4);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Ranged level!");
			break;

			case 5:
				leveledUpSkill = 5;
				leveledUp[5] = true;
				frames.sendMessage(this, "You've just advanced an Prayer level! You have reached level " + skillLvl[5] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Prayer level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[5] + "!", 740, 1);
				frames.setConfig(this, 1179, 5);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Prayer level!");
			break;

			case 6:
				leveledUpSkill = 6;
				leveledUp[6] = true;
				frames.sendMessage(this, "You've just advanced a Magic level! You have reached level " + skillLvl[6] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Magic level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[6] + "!", 740, 1);
				frames.setConfig(this, 1179, 6);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Magic level!");
			break;

			case 7:
				leveledUpSkill = 7;
				leveledUp[7] = true;
				frames.sendMessage(this, "You've just advanced a Cooking level! You have reached level " + skillLvl[7] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Cooking level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[7] + "!", 740, 1);
				frames.setConfig(this, 1179, 7);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Cooking level!");
			break;

			case 8:
				leveledUpSkill = 8;
				leveledUp[8] = true;
				frames.sendMessage(this, "You've just advanced a Woodcutting level! You have reached level " + skillLvl[8] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Woodcutting level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[8] + "!", 740, 1);
				frames.setConfig(this, 1179, 8);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Woodcutting level!");
			break;

			case 9:
				leveledUpSkill = 9;
				leveledUp[9] = true;
				frames.sendMessage(this, "You've just advanced a Fletching level! You have reached level " + skillLvl[9] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Fletching level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[9] + "!", 740, 1);
				frames.setConfig(this, 1179, 9);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Fletching level!");
			break;

			case 10:
				leveledUpSkill = 10;
				leveledUp[10] = true;
				frames.sendMessage(this, "You've just advanced a Fishing level! You have reached level " + skillLvl[10] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Fishing level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[10] + "!", 740, 1);
				frames.setConfig(this, 1179, 10);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Fishing level!");
			break;
			
			case 11:
				leveledUpSkill = 11;
				leveledUp[11] = true;
				frames.sendMessage(this, "You've just advanced a Firemaking level! You have reached level " + skillLvl[11] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Firemaking level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[11] + "!", 740, 1);
				frames.setConfig(this, 1179, 11);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Firemaking level!");
			break;
			
			case 12:
				leveledUpSkill = 12;
				leveledUp[12] = true;
				frames.sendMessage(this, "You've just advanced a Crafting level! You have reached level " + skillLvl[12] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Crafting level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[12] + "!", 740, 1);
				frames.setConfig(this, 1179, 12);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Crafting level!");
			break;
			
			case 13:
				leveledUpSkill = 13;
				leveledUp[13] = true;
				frames.sendMessage(this, "You've just advanced a Smithing level! You have reached level " + skillLvl[13] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Smithing level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[13] + "!", 740, 1);
				frames.setConfig(this, 1179, 13);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Smithing level!");
			break;
			
			case 14:
				leveledUpSkill = 14;
				leveledUp[14] = true;
				frames.sendMessage(this, "You've just advanced a Mining level! You have reached level " + skillLvl[14] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Mining level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[14] + "!", 740, 1);
				frames.setConfig(this, 1179, 14);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Mining level!");
			break;
			
			case 15:
				leveledUpSkill = 15;
				leveledUp[15] = true;
				frames.sendMessage(this, "You've just advanced a Herblore level! You have reached level " + skillLvl[15] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Herblore level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[15] + "!", 740, 1);
				frames.setConfig(this, 1179, 15);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Herblore level!");
			break;

			case 16:
				leveledUpSkill = 16;
				leveledUp[16] = true;
				frames.sendMessage(this, "You've just advanced a Agility level! You have reached level " + skillLvl[16] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Agility level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[16] + "!", 740, 1);
				frames.setConfig(this, 1179, 16);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Agility level!");
			break;

			case 17:
				leveledUpSkill = 17;
				leveledUp[17] = true;
				frames.sendMessage(this, "You've just advanced a Thieving level! You have reached level " + skillLvl[17] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Thieving level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[17] + "!", 740, 1);
				frames.setConfig(this, 1179, 17);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Thieving level!");
			break;

			case 18:
				leveledUpSkill = 18;
				leveledUp[18] = true;
				frames.sendMessage(this, "You've just advanced a Slayer level! You have reached level " + skillLvl[18] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Slayer level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[18] + "!", 740, 1);
				frames.setConfig(this, 1179, 18);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Slayer level!");
			break;

			case 19:
				leveledUpSkill = 19;
				leveledUp[19] = true;
				frames.sendMessage(this, "You've just advanced a Farming level! You have reached level " + skillLvl[19] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Farming level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[19] + "!", 740, 1);
				frames.setConfig(this, 1179, 19);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Farming level!");
			break;

			case 20:
				leveledUpSkill = 20;
				leveledUp[20] = true;
				frames.sendMessage(this, "You've just advanced a Runecrafting level! You have reached level " + skillLvl[20] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Runecrafting level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[20] + "!", 740, 1);
				frames.setConfig(this, 1179, 20);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Runecrafting level!");
			break;
			
			case 21:
				leveledUpSkill = 21;
				leveledUp[21] = true;
				frames.sendMessage(this, "You've just advanced a Construction level! You have reached level " + skillLvl[21] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Construction level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[21] + "!", 740, 1);
				frames.setConfig(this, 1179, 21);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Construction level!");
			break;
			
			case 22:
				leveledUpSkill = 22;
				leveledUp[22] = true;
				frames.sendMessage(this, "You've just advanced a Hunter level! You have reached level " + skillLvl[22] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Hunter level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[22] + "!", 740, 1);
				frames.setConfig(this, 1179, 22);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Hunter level!");
			break;
			
			case 23:
				leveledUpSkill = 23;
				leveledUp[23] = true;
				frames.sendMessage(this, "You've just advanced a Summoning level! You have reached level " + skillLvl[23] + ".");
				frames.setString(this, "Congratulations, you have just advanced a Summoning level!", 740, 0);
				frames.setString(this, "You have now reached level " + skillLvl[23] + "!", 740, 1);
				frames.setConfig(this, 1179, 23);
				frames.showChatboxInterface(this, 740);
				frames.sendMessage(this, "Congratulations, You have just advanced a new Summoning level!");
			break;

			default:
				frames.sendMessage(this, "This level is unknown, Please report this to an administrator.");
			break;
		}
		if (skillLvl[skillId] > 99) {
			skillLvl[skillId] = 99;
			skillXP[skillId] = 13100000;
		}
		requestGFX(1635, 0);
		appearanceUpdateReq = true;
		updateReq = true;
	}
	frames.setSkillLvl(this, skillId);
    }

    public void WalkingTo(int x, int y) {
        int firstX = x - (mapRegionX - 6) * 8;
        int firstY = y - (mapRegionY - 6) * 8;
        Engine.playerMovement.resetWalkingQueue(this);
        Engine.playerMovement.addToWalkingQueue(this, firstX, firstY);
            appearanceUpdateReq = true;
            updateReq = true;
    }

    /**
     * Checks special amount and gets config.
     */
     public void checkAmount() {
	int amount = specAmount;
	if (amount == 1000) {
		frames.setConfig2(this, 300, 1000);
	} else if (amount >= 800) {
		frames.setConfig2(this, 300, 900);
	} else if (amount >= 600) {
		frames.setConfig2(this, 300, 790);
	} else if (amount >= 500) {
		frames.setConfig2(this, 300, 500);
	} else if (amount >= 400) {
		frames.setConfig2(this, 300, 400);
	} else if (amount >= 200) {
		frames.setConfig2(this, 300, 200);
	} else if (amount >= 0) {
		frames.setConfig2(this, 300, 0);
	} else {
	}
    }

    /**
     * Walking request.
     */
    public void playerWalk(int x, int y, int emote, int delay) {
        int firstX = x - (mapRegionX - 6) * 8;
        int firstY = y - (mapRegionY - 6) * 8;
        Engine.playerMovement.resetWalkingQueue(this);
        Engine.playerMovement.addToWalkingQueue(this, firstX, firstY);
        appearanceUpdateReq = true;
        updateReq = true;
    }

    public boolean inWilderness() {
	return absX >= 3136 && absX <= 3350 && absY >= 3523 && absY <= 3597;
    }

    /**
     * Cross wilderness ditch
     */
    public void crossDitch() {
	clickDelay = 5;
	int firstX = 0, firstY = 0;
	if (Server.engine.wildernessArea(absX, absY)) {
		frames.removeOverlay(this);
		firstX = absX - (mapRegionX - 6) * 8;
		firstY = absY-3 - (mapRegionY - 6) * 8;
	} else {
		frames.setString(this, "Level: " + getWildernessLevel(), 381, 1);
		frames.setOverlay(this, 381);
		firstX = absX - (mapRegionX - 6) * 8;
        	firstY = absY+3 - (mapRegionY - 6) * 8;
	}
        Engine.playerMovement.resetWalkingQueue(this);
        Engine.playerMovement.addToWalkingQueue(this, firstX, firstY);
	walkEmote = 2750;
        appearanceUpdateReq = true;
        updateReq = true;
    }

    /**
     * Used to check if player has runes required for vengeance.
     */
    public boolean vengRunes() {
	if (Engine.playerItems.invItemCount(this, 560) > 3 &&
	    Engine.playerItems.invItemCount(this, 557) > 10 &&
	    Engine.playerItems.invItemCount(this, 9075) > 4) {
		return true;
	}
    return false;
    }

    /**
     * Used to check if player has runes required for Cure me spell.
     */
    public boolean cureMeRunes() {
	if (Engine.playerItems.invItemCount(this, 563) > 1 &&
	    Engine.playerItems.invItemCount(this, 564) > 2 &&
	    Engine.playerItems.invItemCount(this, 9075) > 2) {
		return true;
	}
    return false;
    }

    /**
     * Removes runes.
     */
    public void removeRunes(String spellName) {
	PlayerItems playerItems = new PlayerItems();
	if (spellName == "veng") {
		playerItems.deleteItem(this, 560, playerItems.getItemSlot(this, 560), 2);
		playerItems.deleteItem(this, 557, playerItems.getItemSlot(this, 557), 10);
		playerItems.deleteItem(this, 9075, playerItems.getItemSlot(this, 9075), 4);
	}
	if (spellName == "cureme") {
		playerItems.deleteItem(this, 563, playerItems.getItemSlot(this, 563), 1);
		playerItems.deleteItem(this, 564, playerItems.getItemSlot(this, 564), 2);
		playerItems.deleteItem(this, 9075, playerItems.getItemSlot(this, 9075), 2);
	}
	if (spellName == "curegroup") {
		playerItems.deleteItem(this, 563, playerItems.getItemSlot(this, 563), 2);
		playerItems.deleteItem(this, 564, playerItems.getItemSlot(this, 564), 2);
		playerItems.deleteItem(this, 9075, playerItems.getItemSlot(this, 9075), 2);
	}
	if (spellName == "dream") {
		playerItems.deleteItem(this, 559, playerItems.getItemSlot(this, 559), 5);
		playerItems.deleteItem(this, 564, playerItems.getItemSlot(this, 564), 1);
		playerItems.deleteItem(this, 9075, playerItems.getItemSlot(this, 9075), 2);
	}
	if (spellName == "bakepie") {
		playerItems.deleteItem(this, 554, playerItems.getItemSlot(this, 554), 5);
		playerItems.deleteItem(this, 555, playerItems.getItemSlot(this, 555), 4);
		playerItems.deleteItem(this, 9075, playerItems.getItemSlot(this, 9075), 1);
	}
	if (spellName == "hunter") {
		playerItems.deleteItem(this, 557, playerItems.getItemSlot(this, 557), 2);
		playerItems.deleteItem(this, 9075, playerItems.getItemSlot(this, 9075), 2);
	}
	if (spellName == "spellbookswap") {
		playerItems.deleteItem(this, 564, playerItems.getItemSlot(this, 564), 2);
		playerItems.deleteItem(this, 563, playerItems.getItemSlot(this, 563), 1);
		playerItems.deleteItem(this, 9075, playerItems.getItemSlot(this, 9075), 3);
	}
	if (spellName == "humidify") {
		playerItems.deleteItem(this, 564, playerItems.getItemSlot(this, 564), 1);
		playerItems.deleteItem(this, 563, playerItems.getItemSlot(this, 563), 3);
		playerItems.deleteItem(this, 9075, playerItems.getItemSlot(this, 9075), 1);
	}
	if (spellName == "barb") {
		playerItems.deleteItem(this, 554, playerItems.getItemSlot(this, 554), 3);
		playerItems.deleteItem(this, 563, playerItems.getItemSlot(this, 563), 2);
		playerItems.deleteItem(this, 9075, playerItems.getItemSlot(this, 9075), 2);
	}
	if (spellName == "catherby") {
		playerItems.deleteItem(this, 555, playerItems.getItemSlot(this, 555), 10);
		playerItems.deleteItem(this, 563, playerItems.getItemSlot(this, 563), 3);
		playerItems.deleteItem(this, 9075, playerItems.getItemSlot(this, 9075), 3);
	}
	if (spellName == "khazard") {
		playerItems.deleteItem(this, 555, playerItems.getItemSlot(this, 554), 4);
		playerItems.deleteItem(this, 563, playerItems.getItemSlot(this, 563), 2);
		playerItems.deleteItem(this, 9075, playerItems.getItemSlot(this, 9075), 2);
	}
	if (spellName == "waterbirth") {
		playerItems.deleteItem(this, 555, playerItems.getItemSlot(this, 555), 1);
		playerItems.deleteItem(this, 563, playerItems.getItemSlot(this, 563), 1);
		playerItems.deleteItem(this, 9075, playerItems.getItemSlot(this, 9075), 1);
	}
	if (spellName == "groupmoonclan") {
		playerItems.deleteItem(this, 557, playerItems.getItemSlot(this, 557), 4);
		playerItems.deleteItem(this, 563, playerItems.getItemSlot(this, 563), 1);
		playerItems.deleteItem(this, 9075, playerItems.getItemSlot(this, 9075), 2);
	}
    }

    /**
     * Boolean which returns coords ids to get safezone of bounty hunter place.
     */
   /* public boolean pkArenaPart1() {
	return absX >= 3067 && absX <= 3134 && absY >= 3650 && absY <= 3698;
    }

    public boolean pkArenaPart2() {
	return absX >= 3135 && absX <= 3144 && absY >= 3672 && absY <= 3714;
    }

    public boolean inPkArena() {
	return pkArenaPart1() && pkArenaPart2();
    }*/

    /**
     * Updates stats. (Potion use)
     */
    void updateStats() {
	if (usingPotion) {
		if (atkPot) {
			if (skillLvl[0] == getLevelForXP(0)) {
				atkPot = false;
				return;
			}
			potionType = 0;
			skillLvl[0]--;
			statDelay = 45;
		}
		if (strPot) {
			if (skillLvl[2] == getLevelForXP(2)) {
				strPot = false;
				return;
			}
			potionType = 2;
			skillLvl[2]--;
			statDelay = 45;
		}
		if (defPot) {
			if (skillLvl[1] == getLevelForXP(1)) {
				defPot = false;
				return;
			}
			potionType = 1;
			skillLvl[1]--;
			statDelay = 45;
		}
		if (rangePot) {
			if (skillLvl[4] == getLevelForXP(4)) {
				rangePot = false;
				return;
			}
			potionType = 4;
			skillLvl[4]++;
			statDelay = 45;
		}
		frames.setSkillLvl(this, 0);
		frames.setSkillLvl(this, 1);
		frames.setSkillLvl(this, 2);
		frames.setSkillLvl(this, 3);
		frames.setSkillLvl(this, 4);
		frames.setSkillLvl(this, 6);
		appearanceUpdateReq = true;
		updateReq = true;
	}
    }

    private int getPotionType() {
	switch (potionType) {

		/* Attack skill */
		case 0: return 0;
		/* Defence skill */
		case 1: return 1;
		/* Strength skill */
		case 2: return 2;
		case 4: return 4;
		/* Dragon battleAxe effect */
		case 3: return 1;

		default:
			return -1;
	}
    }

    /**
     * Unequip and delete all items player has.
     */
	 	    public int getPlayerKiller()
    {
        int Killer = 0;
        int Count = 0;
        for(int i = 1; i < Engine.players.length; i++)
        {
            if(Killer == 0)
            {
                Killer = i;
                Count = 1;
            }
            else
            {
                if(killedBy[i] > killedBy[Killer])
                {
                    Killer = i;
                    Count = 1;
                }
                else if(killedBy[i] == killedBy[Killer])
                    Count++;
            }
        }
        if(Count > 1)
            Killer = playerId;
        return Killer;
    }
	     public void dropAllItems(int playerGetId)
    {
        if(playerGetId <= 0 || Engine.players[playerGetId] == null)
        {
            playerGetId = playerId;
        }
        Player p2 = Engine.players[playerGetId];
        PlayerItems pi = new PlayerItems();
        if(playerGetId != playerId)
        {
            p2.frames.sendMessage(p2, username + " regrets the day they met you in combat.");
        }
        Engine.items.createGroundItem(526, 1, absX, absY, heightLevel, p2.username);
        for(int i = 0; i < items.length; i++)
        {
            if(items[i] > 0)
            {
                if(Engine.items.isUntradable((items[i])))
                {
                    Engine.items.createGroundItem(items[i], itemsN[i], absX, absY, heightLevel, username);
                    Engine.playerItems.deleteItem(this, items[i], pi.getItemSlot(this, items[i]), itemsN[i]);
                }
                else
                {
                    Engine.items.createGroundItem(items[i], itemsN[i], absX, absY, heightLevel, p2.username);
                    Engine.playerItems.deleteItem(this, items[i], pi.getItemSlot(this, items[i]), itemsN[i]);
                }
            }
        }
        for(int i = 0; i < equipment.length; i++)
        {
            if(equipment[i] > 0)
            {
				frames.removeEquipment(this, equipment[i], i);
                if(Engine.items.isUntradable((items[0])))
                {
                    Engine.items.createGroundItem(items[0], itemsN[0], absX, absY, heightLevel, username);
                    Engine.playerItems.deleteItem(this, items[0], pi.getItemSlot(this, items[0]), itemsN[0]);

                }
                else
                {
                    Engine.items.createGroundItem(items[0], itemsN[0], absX, absY, heightLevel, p2.username);
                    Engine.playerItems.deleteItem(this, items[0], pi.getItemSlot(this, items[0]), itemsN[0]);
                }
            }
        }
        pi = null;
    }
    public void dropAllStuff() {
	if (this == null)
		return;
	PlayerItems pi = new PlayerItems();
        for(int i = 0; i < items.length; i++)
        {
	    if(items[i] == 6570)
		break;
            if(items[i] >= 0)
            {
                if(Engine.items.isUntradable((items[i])))
                {
                    Engine.playerItems.deleteItem(this, items[i], pi.getItemSlot(this, items[i]), itemsN[i]);
                }
                else
                {
                    Engine.playerItems.deleteItem(this, items[i], pi.getItemSlot(this, items[i]), itemsN[i]);
                }
            }
        }
        for(int i = 0; i < equipment.length; i++)
        {
	    if(equipment[i] == 6570)
		break;
            if(equipment[i] >= 0)
            {
		frames.removeEquipment(this, equipment[i], i);
                if(Engine.items.isUntradable((items[0])))
                {
                    Engine.playerItems.deleteItem(this, items[0], pi.getItemSlot(this, items[0]), itemsN[0]);

                }
                else
                {
                    Engine.playerItems.deleteItem(this, items[0], pi.getItemSlot(this, items[0]), itemsN[0]);
                }
            }
        }
	combatType = 0;
    }

    /**
     * drops stuff of enemy.
     * @param killerId the player id of the enemy.
     */
    void dropStuff(int killerId) {
	if (this == null)
		return;

	PlayerItems pi = new PlayerItems();
	Player pKill = Server.engine.players[killerId];
	pKill.PKPointz += 10;
	pKill.frames.sendMessage(pKill, "You gain 10 PKPointz for your slaughter!");
	if (Server.engine.players[killerId] != null) {
        	for(int i = 0; i < items.length; i++) {
            		if(items[i] >= 0) {
                		if(Engine.items.isUntradable((items[i]))) {
                    			Engine.items.createGroundItem(items[i], itemsN[i], absX, absY, heightLevel, username);
                    			Engine.playerItems.deleteItem(this, items[i], pi.getItemSlot(this, items[i]), itemsN[i]);
                		} else {
								Engine.items.createGroundItem(items[i], itemsN[i], absX, absY, heightLevel, Server.engine.players[killerId].username);
                    			Engine.playerItems.deleteItem(this, items[i], pi.getItemSlot(this, items[i]), itemsN[i]);
                		}
            		}
        	}
        	for(int i = 0; i < equipment.length; i++) {
            		if(equipment[i] >= 0) {
							frames.sendMessage(this, "You have lost 5 PKPointz upon death!");
							PKPointz -= 5;
							frames.removeEquipment(this, equipment[i], i);
                		if(Engine.items.isUntradable((items[0]))) {
                    			Engine.items.createGroundItem(items[0], itemsN[0], absX, absY, heightLevel, username);
                    			Engine.playerItems.deleteItem(this, items[0], pi.getItemSlot(this, items[0]), itemsN[0]);
			
				} else {
								
                    			Engine.items.createGroundItem(items[0], itemsN[0], absX, absY, heightLevel, Server.engine.players[killerId].username);
                    			Engine.playerItems.deleteItem(this, items[0], pi.getItemSlot(this, items[0]), itemsN[0]);
                		}
            		}
			Engine.items.createGroundItem(items[0], itemsN[0], absX, absY, heightLevel, Server.engine.players[killerId].username);
        	}
	} else {
        	for(int i = 0; i < items.length; i++) {
            		if(items[i] >= 0) {
                		if(Engine.items.isUntradable((items[i]))) {
                    			Engine.items.createGroundItem(items[i], itemsN[i], absX, absY, heightLevel, username);
                    			Engine.playerItems.deleteItem(this, items[i], pi.getItemSlot(this, items[i]), itemsN[i]);
                		} else {
                   			Engine.items.createGroundItem(items[i], itemsN[i], absX, absY, heightLevel, "");
                    			Engine.playerItems.deleteItem(this, items[i], pi.getItemSlot(this, items[i]), itemsN[i]);
                		}
            		}
        	}
        	for(int i = 0; i < equipment.length; i++) {
            		if(equipment[i] >= 0) {
				frames.removeEquipment(this, equipment[i], i);
                		if(Engine.items.isUntradable((items[0]))) {
                    			Engine.items.createGroundItem(items[0], itemsN[0], absX, absY, heightLevel, username);
                    			Engine.playerItems.deleteItem(this, items[0], pi.getItemSlot(this, items[0]), itemsN[0]);
				} else {
                    			Engine.items.createGroundItem(items[0], itemsN[0], absX, absY, heightLevel, "");
                    			Engine.playerItems.deleteItem(this, items[0], pi.getItemSlot(this, items[0]), itemsN[0]);
                		}
            		}
        	}
		Engine.items.createGroundItem(items[0], itemsN[0], absX, absY, heightLevel, "");
	}
	combatType = 0;
	
    }

    public void resetPrayer() {
	for (int i = 83; i < 101; i++)
		frames.setConfig(this, i, 0);
		frames.setConfig(this, 1052, 0);
		frames.setConfig(this, 1053, 0);
		magicPrayer = false;
		rangedPrayer = false;
		meleePrayer = false;
		retriPrayer = false;
		redempPrayer = false;
		smitePrayer = false;
		chilvaryPrayer = false;
		pietyPrayer = false;
		usingPrayer = false;
		clarity = false;
		improvedReflex = false;
		incredibleReflex = false;
		thickSkin = false;
		rockSkin = false;
		steelSkin = false;
		burstOfStr = false;
		superHumanStr = false;
		ultimateStr = false;
		eagleEyePrayer = false;
		headIconPrayer = -1;
		drainDelay = 0;
    }

    void drainPrayer() {
	if (usingPrayer) {
		if (drainDelay == 0) {
			if (skillLvl[5] <= 1) {
				resetPrayer();
				skillLvl[5] = 0;
				frames.setSkillLvl(this, 5);
				appearanceUpdateReq = true;
				updateReq = true;
				frames.sendMessage(this, "You have run out of prayer points!");
				return;
			}
			skillLvl[5]--;
			frames.setSkillLvl(this, 5);
		}
		drainDelay = 8;
		appearanceUpdateReq = true;
		updateReq = true;
	}
    }

    public void setBattleAxeStats() {
		/**
		 * Strength stats.
		 */
		int abc2 = 0;
		int abc = getLevelForXP(2);
		int abc1 = abc / 10;
		abc2 = abc1 * 2;
		if (abc2 <= 1) {
			abc2 = 2;
		}
		skillLvl[2] = getLevelForXP(2);
		skillLvl[2] += abc2;
		statDelay = 18;
		potionType = 2;
		usingPotion = true;
		frames.setSkillLvl(this, 2);
    }

    public void appendWilderness() {
	if (Engine.inWilderness(this)) {
		frames.setOverlay(this, 381);
		wildyLevel = wildernessLevels(absY);
		frames.setString(this, "Level "+wildyLevel, 381, 1);
	}
    }

    public int wildernessLevels(int coordY) {
		wildyLevel = (coordY - 3254 / 7);
		if (wildyLevel < 1)
			wildyLevel = 1;
		return wildyLevel;
    }

    public boolean inEdge() {
	return absX >= 3040 && absX <= 3125 && absY >= 3523 && absY <= 3551;
    }

    /**
     * Dharok's equipment check.
     */
    public boolean fullDharok() {
	return equipment[3] == 4718 && equipment[4] == 4720 && equipment[7] == 4722 && equipment[0] == 4716;
    }

    /**
     * Verac's equipment check.
     */
    public boolean fullVerac() {
	return equipment[3] == 4755 && equipment[4] == 4757 && equipment[7] == 4759 && equipment[0] == 4753;
    }

    /**
     * Torag equipment check
     */
    public boolean fullTorag() {
	return equipment[3] == 4745 && equipment[4] == 4747 && equipment[7] == 4749 && equipment[0] == 4751;
    }


   /**
    * Guthan equipment chck
    */
   public boolean hasGuthanEquipment() {
	return equipment[3] == 4726 && equipment[4] == 4728 && equipment[7] == 4730 && equipment[0] == 4724;
   }

    /**
     * Safezone.
     */
    public boolean inClan() {
 	return absX >= 3264 && absY >= 3672 && absX <= 3279 && absY <= 3695;
    }

    /**
     * clan wars arena
     */
    public boolean inClanFight() {
	return absX >= 3258 && absY >= 3710 && absX <= 3330 && absY <= 3842;
    }

    public void addClanWarsScreen() {
	frames.setString(this, ""+Server.engine.getWhiteClanPlayerCount(whiteCount)+"", 265, 6);
	frames.setString(this, ""+Server.engine.getBlackClanPlayerCount(blackCount)+"", 265, 7);
	frames.setOverlay(this, 265);
    }

    public int distanceToPoint(int pointX, int pointY) {
	return (int) Math.sqrt(Math.pow(absX - pointX, 2) + Math.pow(absY - pointY, 2));
    }

    public boolean fullVoidKnightRange() {
	return equipment[0] == 11675 && equipment[4] == 8839 && equipment[7] == 8840 && equipment[9] == 8842;
    }

    public boolean fullArmadyl() {
	return equipment[0] == 11718 && equipment[4] == 11720 && equipment[7] == 11722;
    }

    public boolean saraChamber() {
	return absX >= 2889 && absX <= 2907 && absY >= 5258 && absY <= 5276;
    }

    public boolean zammyChamber() {
	return absX >= 2919 && absX <= 2935 && absY >= 5319 && absY <= 5330;
    }

    public boolean graardorChamber() {
	return absX >= 2864 && absX <= 2876 && absY >= 5351 && absY <= 5369;
    }

    public boolean armadylChamber() {
	return absX >= 2823 && absX <= 2843 && absY >= 5295 && absY <= 5310;
    }

    public boolean armadylChamber1() {
	return absX >= 2825 && absX <= 2841 && absY >= 5297 && absY <= 5307;
    }

    public boolean inMageArena() {
	return absX >= 3079 && absX <= 3126 && absY >= 3906 && absY <= 3951;
    }

    public boolean inDuelArena() {
	return absX >= 3349 && absX <= 3388 && absY >= 3262 && absY <= 3280;
    }

    public boolean godWarsDung() {
	return absX >= 2819 && absX <= 2946 && absY >= 5254 && absY <= 5362;
    }

    public boolean inJadCave() {
	return absX >= 2375 && absX <= 2425 && absY >= 5128 && absY <= 5169;
    }

    /**
     * Sets the strings for kill counts for god wars dungeon.
     */
    public void setGodWarsStrings() {
	if (zammyChamber() || addZamorakCheckEventGodWars())
		for (int i = 7; i <  11; i++)
			for (int k = 0; k < 5; k++)
 				if (this != null)
					frames.setString(this, ""+godWarsKills[k]+"", 598, i);
	else
		for (int s = 7; s <  11; s++)
			for (int d = 0; d < 5; d++)
				if (this != null)
					frames.setString(this, ""+godWarsKills[d]+"", 601, s);
    }

    public DuelArena getDuelClass() {
	return duelArena;
    }

    public FightCave getFightClass() {
	return fCave;
    }

    public WarriorGuild getWarriorClass() {
	return warriorGuild;
    }

    public QuestDevelopment getQuestClass() {
	return quest;
    }

    public ByteVector getByteVector() {
	return stream;
    }

    public boolean duelFight() {
	return absX >= 3361 && absX <= 3392 && absY >= 3223 && absY <= 3241;
    }
    public boolean BHOutside() {
	return absX >= 3152 && absX <= 3195 && absY >= 3669 && absY <= 3704;
    }
    public boolean BHOutside2() {
	return absX >= 3146 && absX <= 3166 && absY >= 3662 && absY <= 3668;
    }
    public boolean slayerTower() {
	return absX >= 3402 && absX <= 3458 && absY >= 3529 && absY <= 3581;
    }

    public void appendPotion() {
	if (explodeDelay == 0) {
		if (explodeType == 1) {
			appendHit(25, 0);
			requestForceChat("Ow!");
			frames.sendMessage(this, "The unidentified liquid potion exploded!");
		}
		explodeType = 0;
		explodeDelay = -1;
	}
    }

    public boolean castleLobby() {
	return absX >= 2435 && absX <= 2449 && absY >= 3079 && absY <= 3099;
    }

    public boolean castleArea() {
	return absX >= 2358 && absX <= 2438 && absY >= 3066 && absY <= 3142;
    }

    public boolean correctDistance(int j, int k, int l, int i1, int j1)
    {
        for(int k1 = 0; k1 <= j1; k1++)
        {
            for(int l1 = 0; l1 <= j1; l1++)
            {
                if(j + k1 == l && (k + l1 == i1 || k - l1 == i1 || k == i1))
                    return true;
                if(j - k1 == l && (k + l1 == i1 || k - l1 == i1 || k == i1))
                    return true;
                if(j == l && (k + l1 == i1 || k - l1 == i1 || k == i1))
                    return true;
            }

        }

        return false;
    }

    public void reqWalkQueueX(int x, int y) {
        int firstX = x - (mapRegionX - 6) * 8;
        int firstY = y - (mapRegionY - 6) * 8;
        Engine.playerMovement.resetWalkingQueue(this);
        Engine.playerMovement.addStepToWalkingQueue(firstX, firstY, this);
		Engine.playerMovement.addStepToWalkingQueue(firstX+1, firstY, this);
		Engine.playerMovement.addStepToWalkingQueue(firstX+2, firstY, this);
		Engine.playerMovement.addStepToWalkingQueue(firstX+3, firstY, this);
		Engine.playerMovement.addStepToWalkingQueue(firstX+4, firstY, this);
		Engine.playerMovement.addStepToWalkingQueue(firstX+5, firstY, this);
		Engine.playerMovement.addStepToWalkingQueue(firstX+6, firstY, this);
		Engine.playerMovement.addStepToWalkingQueue(firstX+7, firstY, this);
		Engine.playerMovement.addStepToWalkingQueue(firstX+8, firstY, this);
    }
    public void reqWalkQueue(int x, int y) {
        int firstX = x - (mapRegionX - 6) * 8;
        int firstY = y - (mapRegionY - 6) * 8;
        Engine.playerMovement.resetWalkingQueue(this);
        Engine.playerMovement.addStepToWalkingQueue(firstX, firstY, this);
		Engine.playerMovement.addStepToWalkingQueue(firstX, firstY+1, this);
		Engine.playerMovement.addStepToWalkingQueue(firstX, firstY+2, this);
    }	
	
    public void reqWalkQueueBack(int x, int y) {
        int firstX = x - (mapRegionX - 6) * 8;
        int firstY = y - (mapRegionY - 6) * 8;
        Engine.playerMovement.resetWalkingQueue(this);
        Engine.playerMovement.addStepToWalkingQueue(firstX, firstY, this);
		Engine.playerMovement.addStepToWalkingQueue(firstX, firstY-1, this);
		Engine.playerMovement.addStepToWalkingQueue(firstX, firstY-2, this);
    }

    public int getLoginSpecial() {
	if (specAmount <= 0)
		return 0;
	else if (specAmount == 250)
		return 250;
	else if (specAmount == 500)
		return 500;
	else if (specAmount == 750)
		return 750;
	else if (specAmount == 1000)
		return 1000;
	return 0;
    }

    public PlayerFletching getFletchingClass() {
	return fletchingClass;
    }

    /**
     * Edgeville 1 V 1
     */
    public boolean inEdgePk() {
	return absX >= 3040 && absX <= 3118 && absY >= 3522 && absY <= 3553;
    }

    /**
     * Calculates wilderness Levels.
     */
    public int getWildernessLevel() {
	wildLevel = (absY - 3520) / 8 + 1;
	if (wildLevel < 1)
		wildLevel = 1;
	return wildLevel;
    }

    /**
     * Checking if combat level difference is correct for attacking in wild.
     */
    public boolean combatDifference(int cbLvl) {
	return wildLevel >= combatLevel && combatLevel + cbLvl >= wildLevel || cbLvl < combatLevel && combatLevel - wildLevel <= cbLvl || cbLvl == combatLevel;
    }

    /** 
     * Update the wilderness levels.
     */
    void addWildernessUpdating() {
	frames.setString(this, "Level: "+getWildernessLevel(), 381, 1);
	if (updatedLevel != Server.engine.wildernessArea(absX, absY)) {
		updatedLevel = Server.engine.wildernessArea(absX, absY);
		if (updatedLevel && !inClan() && !clanWarsFightArea()) {
			frames.setOverlay(this, 381);
		} else {
			wildyLevel = 0;
			frames.removeOverlay(this);
		}
	}
    }


    /**
     * Loads objects at Map region loading.
     */
    public void loadStaticObjects() {
	frames.addStaticObject(23610, 2, 3509, 9497, 0, 10);
    }


    /**
     * Zammys part of god wars area check boolean
     */
    public boolean addZamorakCheckEventGodWars() {
	return absX >= 2879 && absX <= 2945 && absY >= 5342 && absY <= 5364;
    }

    /**
     * Update the player.
     */
    public void updatePlayer(boolean updateIsNeccesary) {
	appearanceUpdateReq = updateReq = updateIsNeccesary;
    }

    public int getX() {
	return absX;
    }

    public int getY() {
	return absY;
    }

    public int getHeight() {
	return heightLevel;
    }

    public int getPlayerId() {
	return playerId;
    }

    public void convertPlayerToNpc(int npcType) {
	this.npcType = npcType;
    }

    public void updatePlayerAppearance(int walkAnim, int standAnim, int runAnim) {
	standEmote = standAnim;
	walkEmote = walkAnim;
	runEmote = runAnim;
    }

    public void appendToBanned(String player) {
	BufferedWriter bw = null;
	try {
		bw = new BufferedWriter(new FileWriter("./data/banned/bannedusers.dat", true));
		bw.write(player);
		bw.newLine();
		bw.flush();
	} catch (IOException ioe) {
	} finally {
		if (bw != null) {
			try {
			bw.close();
	} catch (IOException ioe2) {
	}
	}
	}
    }

    String Directory = "./data/banned/bannedusers.dat";
    String MaxBan[] = new String[1000];
    String UserThatBan = new String();
    int Ban = 0;

    public void UnBanPlayer(String Player) {
	try {
	BufferedReader dataStream = new BufferedReader(new FileReader("./data/banned/bannedusers.dat"));
	while ((UserThatBan = dataStream.readLine()) != null) {
	if(UserThatBan.equalsIgnoreCase(Player)) {
	} else
		if(!UserThatBan.equalsIgnoreCase(Player)) {
		MaxBan[Ban] = UserThatBan;
		Ban++;
	}
	}
	} catch(Exception e) {
		e.printStackTrace();
	}
	BufferedWriter bw = null;
	try {
	bw = new BufferedWriter(new FileWriter(Directory, false));
		bw.write("");
		bw.flush();
		bw.close();
	} catch(Exception e) {
		e.printStackTrace();
	}
	try {
		bw = new BufferedWriter(new FileWriter("./data/banned/bannedusers.dat", true));
		for(int a = 0; a < MaxBan.length; a++) {
		if(MaxBan[a] != null) {
		bw.write(MaxBan[a]);
		bw.newLine();
		bw.flush();
	}
	}
	bw.close();
	} catch(Exception e) {
		e.printStackTrace();
	}
	Server.loadBannedUsers();
    }

    public boolean nonMultiPlace() {
	return absX >= 3400 && absX <= 3457 && absY >= 3527 && absY <=  3579 && heightLevel == 2;
    }

    public boolean isInDuelArena() {
	return absX >= 3324 && absX <= 3391 && absY >= 3200 && absY <=  3279 && heightLevel == 0;
    }

    public int neededSpecialAmount() {
	switch (equipment[3]) {

		case 861:
		case 4153:
		case 11235:
		case 1305:
		case 4587:
		case 11694:
		case 11698:
		case 3204:
		case 4151:
		case 11700:
		case 10887:
			return 500;

		case 11696:
		case 11730:
			return 1000;
		default:
			return 0;
	}
     }

    public ClanWars getClanWarsHandler() {
	return clanWars;
     }

    public boolean clanWarsFightArea() {
	return absX >= 3263 && absX <= 3327 && absY >= 3713 && absY <= 3840;
    }

    public int getThiefHit() {
	switch (thievingType) {

		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
   			return 1;

		case 9:
			return 5;

	    default:
		return 1;

	}
    }


    /**
     * Player friends list variables and methods
     */
    public List<Long> friends = new ArrayList<Long>(200);
    public List<Long> ignores = new ArrayList<Long>(100);

	public void friendsLoggedIn() {
    		for (Long friend : friends) {
        		frames.sendFriend(this, friend, getWorld(friend));
    		}

    		    long[] array = new long[ignores.size()];
    		    int i = 0;

    		for (Long ignore : ignores) {
        	    if (ignore != null) {
            		array[i++] = ignore;
		    }
    		}

    		    frames.sendIgnores(this, array);
    		    long me = Misc.stringToLong(username);

    		for (Player p : Engine.players) {
        	    if (p == null) {
			continue;
		    }
        	    if (p.friends.contains(me)) {
            		p.frames.sendFriend(p, me, 66);
        	    }
    		}
	}

	public int getWorld(long friend) {
    	    for (Player p : Engine.players) {
        	if(p != null && p.online) {
            	    if (Misc.stringToLong(p.username) == friend) {
                	return 66;
            	    }
        	}
    	    }
    		return 0;
	}

    /**
     * Fishing Method
     */
    public void Fish(Player p, int Exp, int Item, int Emote, String fishingName) {
 	int index = Engine.playerItems.findInvSlot(this);
	int k = skillLvl[10];
	
	    if (index > 0) {
		p.requestAnim(Emote, 0);
		Engine.playerItems.addItem(this, Item, 1);
		//p.appendExperience(Exp, 10);
		p.addSkillXP(Exp, 10);
		p.frames.sendMessage(this, "You caught a "+ fishName +".");
		fishTimer = Misc.random(15 + (k / 8) - fishLvlReq / 4);
		fishAmount -= 1;
		fishName = fishingName;
	    } else {
		resetSkills();
		frames.playSound(this, 2268, 1, 0);
   		p.frames.showChatboxInterface(p, 241);
                p.frames.setString(p, "You have run out of inventory space.", 241, 4);
                p.frames.setString(p, "", 241, 3);
		p.frames.sendMessage(this, "You have run out of inventory space.");
		p.requestAnim(standEmote, 0);
	    }
    }

    /**
     * Cooking Method
     */
    public void Cook(Player p, int Exp, int Item, int cookedItem, String cookedName) {
	if (Engine.playerItems.HasItemAmount(this, Item, 1) == false) {
		resetSkills();
	} else {
		frames.playSound(this, 2577, 1, 0);
		p.requestAnim(883, 0);
		Engine.playerItems.deleteItem(this, Item, Engine.playerItems.getItemSlot(this, Item), 1);
		Engine.playerItems.addItem(this, cookedItem, 1);
		p.addSkillXP(Exp, 7);
		p.frames.sendMessage(this, "You cook the "+ cookedName +".");
		cookTimer = 3;
		cookAmount--;
	}
    }

    /**
     * Fishing Variables
     */
    public int fishTimer = -1;
    public int fishAmount;
    public int fishXP;
    public int fishGet;
    public int fishEmote;
    public int fishLvlReq;
    public String fishName;

    /**
     * Cooking Variables
     */
    public int cookTimer = -1;
    public int cookAmount;
    public int cookXP;
    public int cookGet;
    public int cookID;
    public boolean Cooking;
    public String cookName;

    public void resetSkills() {
	cookTimer = -1;
	cookAmount = 0;
	cookXP = 0;
	cookGet = 0;
	cookID = 0;
	fishTimer = -1;
	fishAmount = 0;
	fishXP = 0;
	fishGet = 0;
	fishEmote = 0;
	fishName = "";
	fishLvlReq = 0;
	Cooking = false;
    }

    /**
     * Bolt spec variable
     */
    public int crossBowDragon;


    /**
     * Thieving variables
     */
    public double hitTimer;
    public int thiefTimer;
    public int thiefDelay;
    public int thievingType;
    public boolean thiefNPC;


    /**
     * NPC Dialogue varables
     */
    public int surgeonTimer;
    public int NpcDialogue = 0;
    public int NpcTalkTo = 0;
    public boolean NpcDialogueSend = false;
    public int NpcWanneTalk = 0;

    /**
     * Level up
     */
    public boolean[] leveledUp = new boolean[24];
    public int leveledUpSkill = 0;
	public int skillMenu = 0;

    /**
     * Resetting animation
     */
    public int resetAnimTimer;

    /**
     * NPC Contact
     */
    public int npcContactTimer;

    /**
     * Spell book swap switch back variable
     */
    public int switchBackTimer;

    /**
     * Lunar 'dream' spell timer
     */
    public int dreamTimer;

    /**
     * The player you are following
     */
    public int followId;

    /**
     * 1v1 variables
     */
    public int cmbResetTimer;
    public int combatWith;

    /**
     * Magic shortbow
     */
    public int msbDelay = -1;

    /**
     * Sound/Music/GFX testing variables
     */
    public int soundId = 2700;
    public int musicId = 0;
    public int gfxIdTesting = 2000;

    /**
     * The player you are attacking
     */
    public int attackPlayer = 0;

    /**
     * Prepare player for removal.
     */
    public void destruct() {

    	long me = Misc.stringToLong(username); 

	for(Player p : Engine.players) {
	    if (p == null) {
		continue;
	    }
	    if (p.friends.contains(me)) {
            	p.frames.sendFriend(p, me, 0);
	    }
	}

        stream = null;
        try {
            socket.input.close();
            socket.output.close();
            socket.socket.close();
        } catch (Exception e) {
        }
        socket.input = null;
        socket.output = null;
        socket.socket = null;
        socket = null;
        absX = absY = mapRegionX = mapRegionY = -1;
    }
}